| 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 // The _GrowableArrayMarker class is used to signal to the List() factory | 5 // The _GrowableArrayMarker class is used to signal to the List() factory |
| 6 // whether a parameter was passed. | 6 // whether a parameter was passed. |
| 7 class _GrowableArrayMarker implements int { | 7 class _GrowableArrayMarker implements int { |
| 8 const _GrowableArrayMarker(); | 8 const _GrowableArrayMarker(); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 result[i] = fill; | 29 result[i] = fill; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 return result; | 32 return result; |
| 33 } | 33 } |
| 34 | 34 |
| 35 /* patch */ factory List.from(Iterable elements, { bool growable: true }) { | 35 /* patch */ factory List.from(Iterable elements, { bool growable: true }) { |
| 36 if (elements is EfficientLength) { | 36 if (elements is EfficientLength) { |
| 37 int length = elements.length; | 37 int length = elements.length; |
| 38 var list = growable ? new _GrowableList<E>(length) : new _List<E>(length); | 38 var list = growable ? new _GrowableList<E>(length) : new _List<E>(length); |
| 39 int i = 0; | 39 if (length > 0) { // Avoid creating iterator unless necessary. |
| 40 for (var element in elements) { list[i++] = element; } | 40 int i = 0; |
| 41 for (var element in elements) { list[i++] = element; } |
| 42 } |
| 41 return list; | 43 return list; |
| 42 } | 44 } |
| 43 List<E> list = new _GrowableList<E>(0); | 45 List<E> list = new _GrowableList<E>(0); |
| 44 for (E e in elements) { | 46 for (E e in elements) { |
| 45 list.add(e); | 47 list.add(e); |
| 46 } | 48 } |
| 47 if (growable) return list; | 49 if (growable) return list; |
| 48 if (list.length == 0) { | 50 if (list.length == 0) { |
| 49 // Avoid getting an immutable list from makeListFixedLength. | 51 // Avoid getting an immutable list from makeListFixedLength. |
| 50 return new List<E>(0); | 52 return new _List<E>(0); |
| 51 } | 53 } |
| 52 return makeListFixedLength(list); | 54 return makeListFixedLength(list); |
| 53 } | 55 } |
| 54 | 56 |
| 55 /* patch */ factory List.unmodifiable(Iterable elements) { | 57 /* patch */ factory List.unmodifiable(Iterable elements) { |
| 56 List result = new List<E>.from(elements, growable: false); | 58 List result = new List<E>.from(elements, growable: false); |
| 57 return makeFixedListUnmodifiable(result); | 59 return makeFixedListUnmodifiable(result); |
| 58 } | 60 } |
| 59 | 61 |
| 60 // Factory constructing a mutable List from a parser generated List literal. | 62 // Factory constructing a mutable List from a parser generated List literal. |
| 61 // [elements] contains elements that are already type checked. | 63 // [elements] contains elements that are already type checked. |
| 62 factory List._fromLiteral(List elements) { | 64 factory List._fromLiteral(List elements) { |
| 63 if (elements.isEmpty) { | 65 if (elements.isEmpty) { |
| 64 return new _GrowableList<E>(0); | 66 return new _GrowableList<E>(0); |
| 65 } | 67 } |
| 66 var result = new _GrowableList<E>.withData(elements); | 68 var result = new _GrowableList<E>.withData(elements); |
| 67 result._setLength(elements.length); | 69 result._setLength(elements.length); |
| 68 return result; | 70 return result; |
| 69 } | 71 } |
| 70 } | 72 } |
| OLD | NEW |