| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 /** | 117 /** |
| 118 * Creates a list containing all [elements]. | 118 * Creates a list containing all [elements]. |
| 119 * | 119 * |
| 120 * The [Iterator] of [elements] provides the order of the elements. | 120 * The [Iterator] of [elements] provides the order of the elements. |
| 121 * | 121 * |
| 122 * This constructor returns a growable list when [growable] is true; | 122 * This constructor returns a growable list when [growable] is true; |
| 123 * otherwise, it returns a fixed-length list. | 123 * otherwise, it returns a fixed-length list. |
| 124 */ | 124 */ |
| 125 factory List.from(Iterable elements, { bool growable: true }) { | 125 factory List.from(Iterable elements, { bool growable: true }) { |
| 126 List<E> list = new List<E>(); | 126 List<E> list = new List<E>(); |
| 127 for (E e in elements) { | 127 for (var e in elements) { |
| 128 list.add(e); | 128 list.add(e); |
| 129 } | 129 } |
| 130 if (growable) return list; | 130 if (growable) return list; |
| 131 return makeListFixedLength(list); | 131 return makeListFixedLength(list); |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Generates a list of values. | 135 * Generates a list of values. |
| 136 * | 136 * |
| 137 * Creates a list with [length] positions and fills it with values created by | 137 * Creates a list with [length] positions and fills it with values created by |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return false; | 269 return false; |
| 270 } | 270 } |
| 271 | 271 |
| 272 bool get isEmpty => length == 0; | 272 bool get isEmpty => length == 0; |
| 273 | 273 |
| 274 bool get isNotEmpty => !isEmpty; | 274 bool get isNotEmpty => !isEmpty; |
| 275 | 275 |
| 276 String toString() => ListBase.listToString(this); | 276 String toString() => ListBase.listToString(this); |
| 277 | 277 |
| 278 List<E> toList({ bool growable: true }) { | 278 List<E> toList({ bool growable: true }) { |
| 279 if (growable) { | 279 // TODO(vsm): Enforce growable / non-growable. |
| 280 return new JSArray<E>.markGrowable(JS('', '#.slice()', this)); | 280 // See: https://github.com/dart-lang/dev_compiler/issues/175 |
| 281 } else { | 281 return JS('', 'dart.setType(#.slice(), core.List\$(#))', this, E); |
| 282 return new JSArray<E>.markFixed(JS('', '#.slice()', this)); | |
| 283 } | |
| 284 } | 282 } |
| 285 | 283 |
| 286 Set<E> toSet() => new Set<E>.from(this); | 284 Set<E> toSet() => new Set<E>.from(this); |
| 287 | 285 |
| 288 Iterator<E> get iterator => new ListIterator<E>(this); | 286 Iterator<E> get iterator => new ListIterator<E>(this); |
| 289 | 287 |
| 290 int get hashCode => Primitives.objectHashCode(this); | 288 int get hashCode => Primitives.objectHashCode(this); |
| 291 | 289 |
| 292 // BORDER XXXX | 290 // BORDER XXXX |
| 293 | 291 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 * | 739 * |
| 742 * List<String> words = ['fee', 'fi', 'fo', 'fum']; | 740 * List<String> words = ['fee', 'fi', 'fo', 'fum']; |
| 743 * Map<int, String> map = words.asMap(); | 741 * Map<int, String> map = words.asMap(); |
| 744 * map[0] + map[1]; // 'feefi'; | 742 * map[0] + map[1]; // 'feefi'; |
| 745 * map.keys.toList(); // [0, 1, 2, 3] | 743 * map.keys.toList(); // [0, 1, 2, 3] |
| 746 */ | 744 */ |
| 747 Map<int, E> asMap() { | 745 Map<int, E> asMap() { |
| 748 return new IterableMixinWorkaround<E>().asMapList(this); | 746 return new IterableMixinWorkaround<E>().asMapList(this); |
| 749 } | 747 } |
| 750 } | 748 } |
| OLD | NEW |