| 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 { | 5 class ListFactory<E> { |
| 6 factory List<E>.from(Iterable<E> other) { | 6 factory List.from(Iterable<E> other) { |
| 7 List<E> list = new List<E>(); | 7 List<E> list = new List<E>(); |
| 8 for (final e in other) { | 8 for (final e in other) { |
| 9 list.add(e); | 9 list.add(e); |
| 10 } | 10 } |
| 11 return list; | 11 return list; |
| 12 } | 12 } |
| 13 | 13 |
| 14 factory List<E>([int length = null]) { | 14 factory List([int length = null]) { |
| 15 bool isFixed = true; | 15 bool isFixed = true; |
| 16 if (length === null) { | 16 if (length === null) { |
| 17 length = 0; | 17 length = 0; |
| 18 isFixed = false; | 18 isFixed = false; |
| 19 } else if (length < 0) { | 19 } else if (length < 0) { |
| 20 throw new IllegalArgumentException("negative length $length"); | 20 throw new IllegalArgumentException("negative length $length"); |
| 21 } | 21 } |
| 22 // TODO(floitsch): make list creation more efficient. Currently we allocate | 22 // TODO(floitsch): make list creation more efficient. Currently we allocate |
| 23 // a new TypeToken at every allocation. Either we can optimize them away, | 23 // a new TypeToken at every allocation. Either we can optimize them away, |
| 24 // or we need to find other ways to pass type-information from Dart to JS. | 24 // or we need to find other ways to pass type-information from Dart to JS. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 259 } |
| 260 | 260 |
| 261 static List _newList(int len) native { | 261 static List _newList(int len) native { |
| 262 return new List(len); | 262 return new List(len); |
| 263 } | 263 } |
| 264 | 264 |
| 265 static void _throwIndexOutOfRangeException(int index) native { | 265 static void _throwIndexOutOfRangeException(int index) native { |
| 266 throw new IndexOutOfRangeException(index); | 266 throw new IndexOutOfRangeException(index); |
| 267 } | 267 } |
| 268 } | 268 } |
| OLD | NEW |