| OLD | NEW |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 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 Loading... |
| 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 } |
| OLD | NEW |