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 14 matching lines...) Expand all Loading... |
25 // of new _List. | 25 // of new _List. |
26 var result = new _List<E>(length); | 26 var result = new _List<E>(length); |
27 if (fill != null) { | 27 if (fill != null) { |
28 for (int i = 0; i < length; i++) { | 28 for (int i = 0; i < length; i++) { |
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 other, { bool growable: true }) { | 35 /* patch */ factory List.from(Iterable elements, { bool growable: true }) { |
36 if (other is EfficientLength) { | 36 if (elements is EfficientLength) { |
37 int length = other.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 int i = 0; |
40 for (var element in other) { list[i++] = element; } | 40 for (var element in elements) { list[i++] = element; } |
41 return list; | 41 return list; |
42 } | 42 } |
43 List<E> list = new _GrowableList<E>(0); | 43 List<E> list = new _GrowableList<E>(0); |
44 for (E e in other) { | 44 for (E e in elements) { |
45 list.add(e); | 45 list.add(e); |
46 } | 46 } |
47 if (growable) return list; | 47 if (growable) return list; |
48 return makeListFixedLength(list); | 48 return makeListFixedLength(list); |
49 } | 49 } |
50 | 50 |
51 // Factory constructing a mutable List from a parser generated List literal. | 51 // Factory constructing a mutable List from a parser generated List literal. |
52 // [elements] contains elements that are already type checked. | 52 // [elements] contains elements that are already type checked. |
53 factory List._fromLiteral(List elements) { | 53 factory List._fromLiteral(List elements) { |
54 if (elements.isEmpty) { | 54 if (elements.isEmpty) { |
55 return new _GrowableList<E>(0); | 55 return new _GrowableList<E>(0); |
56 } | 56 } |
57 var result = new _GrowableList<E>.withData(elements); | 57 var result = new _GrowableList<E>.withData(elements); |
58 result._setLength(elements.length); | 58 result._setLength(elements.length); |
59 return result; | 59 return result; |
60 } | 60 } |
61 } | 61 } |
OLD | NEW |