| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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<T> { | 5 class ListFactory<T> { |
| 6 | 6 |
| 7 factory List.from(Iterable<T> other) { | 7 factory List.from(Iterable<T> other) { |
| 8 GrowableObjectArray<T> list = new GrowableObjectArray<T>(); | 8 GrowableObjectArray<T> list = new GrowableObjectArray<T>(); |
| 9 for (final e in other) { | 9 for (final e in other) { |
| 10 list.add(e); | 10 list.add(e); |
| 11 } | 11 } |
| 12 return list; | 12 return list; |
| 13 } | 13 } |
| 14 | 14 |
| 15 factory List.fromList(List<T> other, int startIndex, int endIndex) { | |
| 16 List list = new List<T>(); | |
| 17 if (endIndex > other.length) endIndex = other.length; | |
| 18 if (startIndex < 0) startIndex = 0; | |
| 19 int count = endIndex - startIndex; | |
| 20 if (count > 0) { | |
| 21 list.length = count; | |
| 22 Arrays.copy(other, startIndex, list, 0, count); | |
| 23 } | |
| 24 return list; | |
| 25 } | |
| 26 | |
| 27 factory List([int length = null]) { | 15 factory List([int length = null]) { |
| 28 if (length === null) { | 16 if (length === null) { |
| 29 return new GrowableObjectArray<T>(); | 17 return new GrowableObjectArray<T>(); |
| 30 } else { | 18 } else { |
| 31 return new ObjectArray<T>(length); | 19 return new ObjectArray<T>(length); |
| 32 } | 20 } |
| 33 } | 21 } |
| 34 } | 22 } |
| 35 | 23 |
| 36 // TODO(srdjan): Use shared array implementation. | 24 // TODO(srdjan): Use shared array implementation. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 if (!hasNext()) { | 295 if (!hasNext()) { |
| 308 throw const NoMoreElementsException(); | 296 throw const NoMoreElementsException(); |
| 309 } | 297 } |
| 310 return _array[_pos++]; | 298 return _array[_pos++]; |
| 311 } | 299 } |
| 312 | 300 |
| 313 final List<T> _array; | 301 final List<T> _array; |
| 314 final int _length; // Cache array length for faster access. | 302 final int _length; // Cache array length for faster access. |
| 315 int _pos; | 303 int _pos; |
| 316 } | 304 } |
| OLD | NEW |