| 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 | 5 |
| 6 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
| 7 class _ObjectArray<E> implements List<E> { | 7 class _ObjectArray<E> implements List<E> { |
| 8 | 8 |
| 9 factory _ObjectArray(int length) native "ObjectArray_allocate"; | 9 factory _ObjectArray(int length) native "ObjectArray_allocate"; |
| 10 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 void set length(int length) { | 131 void set length(int length) { |
| 132 throw new UnsupportedError( | 132 throw new UnsupportedError( |
| 133 "Cannot change the length of a non-extendable array"); | 133 "Cannot change the length of a non-extendable array"); |
| 134 } | 134 } |
| 135 | 135 |
| 136 E removeLast() { | 136 E removeLast() { |
| 137 throw new UnsupportedError( | 137 throw new UnsupportedError( |
| 138 "Cannot remove in a non-extendable array"); | 138 "Cannot remove in a non-extendable array"); |
| 139 } | 139 } |
| 140 | 140 |
| 141 E get first { | |
| 142 return this[0]; | |
| 143 } | |
| 144 | |
| 145 E get last { | 141 E get last { |
| 146 return this[length - 1]; | 142 return this[length - 1]; |
| 147 } | 143 } |
| 148 } | 144 } |
| 149 | 145 |
| 150 | 146 |
| 151 // This is essentially the same class as _ObjectArray, but it does not | 147 // This is essentially the same class as _ObjectArray, but it does not |
| 152 // permit any modification of array elements from Dart code. We use | 148 // permit any modification of array elements from Dart code. We use |
| 153 // this class for arrays constructed from Dart array literals. | 149 // this class for arrays constructed from Dart array literals. |
| 154 // TODO(hausner): We should consider the trade-offs between two | 150 // TODO(hausner): We should consider the trade-offs between two |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 void set length(int length) { | 278 void set length(int length) { |
| 283 throw new UnsupportedError( | 279 throw new UnsupportedError( |
| 284 "Cannot change the length of an immutable array"); | 280 "Cannot change the length of an immutable array"); |
| 285 } | 281 } |
| 286 | 282 |
| 287 E removeLast() { | 283 E removeLast() { |
| 288 throw new UnsupportedError( | 284 throw new UnsupportedError( |
| 289 "Cannot remove in a non-extendable array"); | 285 "Cannot remove in a non-extendable array"); |
| 290 } | 286 } |
| 291 | 287 |
| 292 E get first { | |
| 293 return this[0]; | |
| 294 } | |
| 295 | |
| 296 E get last { | 288 E get last { |
| 297 return this[length - 1]; | 289 return this[length - 1]; |
| 298 } | 290 } |
| 299 } | 291 } |
| 300 | 292 |
| 301 | 293 |
| 302 // Iterator for arrays with fixed size. | 294 // Iterator for arrays with fixed size. |
| 303 class _FixedSizeArrayIterator<E> implements Iterator<E> { | 295 class _FixedSizeArrayIterator<E> implements Iterator<E> { |
| 304 _FixedSizeArrayIterator(List array) | 296 _FixedSizeArrayIterator(List array) |
| 305 : _array = array, _length = array.length, _pos = 0 { | 297 : _array = array, _length = array.length, _pos = 0 { |
| 306 assert(array is _ObjectArray || array is _ImmutableArray); | 298 assert(array is _ObjectArray || array is _ImmutableArray); |
| 307 } | 299 } |
| 308 | 300 |
| 309 bool get hasNext { | 301 bool get hasNext { |
| 310 return _length > _pos; | 302 return _length > _pos; |
| 311 } | 303 } |
| 312 | 304 |
| 313 E next() { | 305 E next() { |
| 314 if (!hasNext) { | 306 if (!hasNext) { |
| 315 throw new StateError("No more elements"); | 307 throw new StateError("No more elements"); |
| 316 } | 308 } |
| 317 return _array[_pos++]; | 309 return _array[_pos++]; |
| 318 } | 310 } |
| 319 | 311 |
| 320 final List<E> _array; | 312 final List<E> _array; |
| 321 final int _length; // Cache array length for faster access. | 313 final int _length; // Cache array length for faster access. |
| 322 int _pos; | 314 int _pos; |
| 323 } | 315 } |
| OLD | NEW |