| 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 class ListFactory<E> { | |
| 6 | |
| 7 factory List.from(Iterable<E> other) { | |
| 8 GrowableObjectArray<E> list = new GrowableObjectArray<E>(); | |
| 9 for (final e in other) { | |
| 10 list.add(e); | |
| 11 } | |
| 12 return list; | |
| 13 } | |
| 14 | |
| 15 factory List([int length = null]) { | |
| 16 if (length === null) { | |
| 17 return new GrowableObjectArray<E>(); | |
| 18 } else { | |
| 19 return new ObjectArray<E>(length); | |
| 20 } | |
| 21 } | |
| 22 } | |
| 23 | 5 |
| 24 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
| 25 class ObjectArray<E> implements List<E> { | 7 class ObjectArray<E> implements List<E> { |
| 26 | 8 |
| 27 factory ObjectArray(int length) native "ObjectArray_allocate"; | 9 factory ObjectArray(int length) native "ObjectArray_allocate"; |
| 28 | 10 |
| 29 E operator [](int index) native "ObjectArray_getIndexed"; | 11 E operator [](int index) native "ObjectArray_getIndexed"; |
| 30 | 12 |
| 31 void operator []=(int index, E value) native "ObjectArray_setIndexed"; | 13 void operator []=(int index, E value) native "ObjectArray_setIndexed"; |
| 32 | 14 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (!hasNext()) { | 300 if (!hasNext()) { |
| 319 throw const NoMoreElementsException(); | 301 throw const NoMoreElementsException(); |
| 320 } | 302 } |
| 321 return _array[_pos++]; | 303 return _array[_pos++]; |
| 322 } | 304 } |
| 323 | 305 |
| 324 final List<E> _array; | 306 final List<E> _array; |
| 325 final int _length; // Cache array length for faster access. | 307 final int _length; // Cache array length for faster access. |
| 326 int _pos; | 308 int _pos; |
| 327 } | 309 } |
| OLD | NEW |