| 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 _ObjectArray. | 25 // of new _ObjectArray. |
| 26 var result = new _ObjectArray<E>(length); | 26 var result = new _ObjectArray<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 }) { |
| 36 // TODO(iposva): Avoid the iterators for the known lists and do the copy in |
| 37 // the VM directly. |
| 38 var len = null; |
| 39 // TODO(iposva): Remove this dance once dart2js does not implement |
| 40 // an Iterable that throws on calling length. |
| 41 try { |
| 42 len = other.length; |
| 43 } catch (e) { |
| 44 // Ensure that we try again below. |
| 45 len = null; |
| 46 } |
| 47 if (len == null) { |
| 48 len = 0; |
| 49 try { |
| 50 var iter = other.iterator; |
| 51 while (iter.moveNext()) { |
| 52 len++; |
| 53 } |
| 54 } catch (e) { |
| 55 rethrow; // Giving up and throwing to the caller. |
| 56 } |
| 57 } |
| 58 var result; |
| 59 if (growable) { |
| 60 result = new _GrowableObjectArray<E>.withCapacity(len); |
| 61 result.length = len; |
| 62 } else { |
| 63 result = new _ObjectArray<E>(len); |
| 64 } |
| 65 var iter = other.iterator; |
| 66 for (var i = 0; i < len; i++) { |
| 67 iter.moveNext(); |
| 68 result[i] = iter.current; |
| 69 } |
| 70 return result; |
| 71 } |
| 72 |
| 35 // Factory constructing a mutable List from a parser generated List literal. | 73 // Factory constructing a mutable List from a parser generated List literal. |
| 36 // [elements] contains elements that are already type checked. | 74 // [elements] contains elements that are already type checked. |
| 37 factory List._fromLiteral(List elements) { | 75 factory List._fromLiteral(List elements) { |
| 38 if (elements.isEmpty) { | 76 if (elements.isEmpty) { |
| 39 return new _GrowableObjectArray<E>(0); | 77 return new _GrowableObjectArray<E>(0); |
| 40 } | 78 } |
| 41 var result = new _GrowableObjectArray<E>.withData(elements); | 79 var result = new _GrowableObjectArray<E>.withData(elements); |
| 42 result._setLength(elements.length); | 80 result._setLength(elements.length); |
| 43 return result; | 81 return result; |
| 44 } | 82 } |
| 45 } | 83 } |
| OLD | NEW |