Chromium Code Reviews| Index: runtime/lib/array.dart |
| diff --git a/runtime/lib/array.dart b/runtime/lib/array.dart |
| index 1fb17fb8ecf4d9927e21e4fbe38cf604fa7fbb67..51055883bf26f462ed8fe93aaea36f0c0f602f86 100644 |
| --- a/runtime/lib/array.dart |
| +++ b/runtime/lib/array.dart |
| @@ -105,9 +105,7 @@ class _ObjectArray<E> implements List<E> { |
| return Arrays.lastIndexOf(this, element, start); |
| } |
| - Iterator<E> iterator() { |
| - return new _FixedSizeArrayIterator<E>(this); |
| - } |
| + Iterator<E> get iterator => new _FixedSizeArrayIterator<E>(this); |
| void add(E element) { |
| throw new UnsupportedError( |
| @@ -252,9 +250,7 @@ class _ImmutableArray<E> implements List<E> { |
| return Arrays.lastIndexOf(this, element, start); |
| } |
| - Iterator<E> iterator() { |
| - return new _FixedSizeArrayIterator<E>(this); |
| - } |
| + Iterator<E> get iterator => new _FixedSizeArrayIterator<E>(this); |
| void add(E element) { |
| throw new UnsupportedError( |
| @@ -294,19 +290,25 @@ class _ImmutableArray<E> implements List<E> { |
| // Iterator for arrays with fixed size. |
| class _FixedSizeArrayIterator<E> implements Iterator<E> { |
| _FixedSizeArrayIterator(List array) |
| - : _array = array, _length = array.length, _pos = 0 { |
| + : _array = array, _length = array.length, _pos = -1 { |
| assert(array is _ObjectArray || array is _ImmutableArray); |
| } |
| + bool moveNext() { |
| + _pos++; |
| + if (_pos < _length) return true; |
| + _pos = _length; |
| + return false; |
| + } |
| bool get hasNext { |
| return _length > _pos; |
| } |
| - E next() { |
| - if (!hasNext) { |
| - throw new StateError("No more elements"); |
| + E get current { |
| + if (0 <= _pos && _pos < _length) { |
| + return _array[_pos]; |
| } |
| - return _array[_pos++]; |
| + throw new StateError("No more elements"); |
|
Lasse Reichstein Nielsen
2012/11/15 10:24:37
Wrong message if _pos < 0 and length > 0.
floitsch
2012/11/16 17:51:58
added TODO. this will go away with the new approac
|
| } |
| final List<E> _array; |