Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: sdk/lib/core/list.dart

Issue 134893003: Add internal operation that converts a growable list to a fixed list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * An indexable collection of objects with a length. 8 * An indexable collection of objects with a length.
9 * 9 *
10 * Subclasses of this class implement different kinds of lists. 10 * Subclasses of this class implement different kinds of lists.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 /** 85 /**
86 * Creates a list and initializes it using the contents of [other]. 86 * Creates a list and initializes it using the contents of [other].
87 * 87 *
88 * The [Iterator] of [other] provides the order of the objects. 88 * The [Iterator] of [other] provides the order of the objects.
89 * 89 *
90 * This constructor returns a growable list if [growable] is true; 90 * This constructor returns a growable list if [growable] is true;
91 * otherwise, it returns a fixed-length list. 91 * otherwise, it returns a fixed-length list.
92 */ 92 */
93 factory List.from(Iterable other, { bool growable: true }) { 93 factory List.from(Iterable other, { bool growable: true }) {
94 List<E> list = new List<E>(); 94 List<E> list = new List<E>();
95 for (E e in other) { 95 for (E e in other) {
floitsch 2014/02/07 15:13:13 I think it would also be more efficient, if you us
96 list.add(e); 96 list.add(e);
97 } 97 }
98 if (growable) return list; 98 if (growable) return list;
99 int length = list.length; 99 return makeListFixedLength(list);
100 List<E> fixedList = new List<E>(length);
101 for (int i = 0; i < length; i++) {
102 fixedList[i] = list[i];
103 }
104 return fixedList;
105 } 100 }
106 101
107 /** 102 /**
108 * Generates a list of values. 103 * Generates a list of values.
109 * 104 *
110 * Creates a list with [length] positions and fills it with values created by 105 * Creates a list with [length] positions and fills it with values created by
111 * calling [generator] for each index in the range `0` .. `length - 1` 106 * calling [generator] for each index in the range `0` .. `length - 1`
112 * in increasing order. 107 * in increasing order.
113 * 108 *
114 * new List<int>.generate(3, (int index) => index * index); // [0, 1, 4] 109 * new List<int>.generate(3, (int index) => index * index); // [0, 1, 4]
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 * as values. The `Map.keys` [Iterable] iterates the indices of this list 454 * as values. The `Map.keys` [Iterable] iterates the indices of this list
460 * in numerical order. 455 * in numerical order.
461 * 456 *
462 * List<String> words = ['fee', 'fi', 'fo', 'fum']; 457 * List<String> words = ['fee', 'fi', 'fo', 'fum'];
463 * Map<int, String> map = words.asMap(); 458 * Map<int, String> map = words.asMap();
464 * map[0] + map[1]; // 'feefi'; 459 * map[0] + map[1]; // 'feefi';
465 * map.keys.toList(); // [0, 1, 2, 3] 460 * map.keys.toList(); // [0, 1, 2, 3]
466 */ 461 */
467 Map<int, E> asMap(); 462 Map<int, E> asMap();
468 } 463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698