Chromium Code Reviews| Index: runtime/lib/array.dart |
| diff --git a/runtime/lib/array.dart b/runtime/lib/array.dart |
| index e047ab2c0878aae3f5e72899069dd2d329bd01a8..79bf3d09613547d23136af6411425cf24e213e11 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); |
|
Ivan Posva
2012/11/26 18:20:13
We like our curly braces. There is no need to remo
floitsch
2012/11/28 13:44:34
Done.
|
| 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); |
|
Ivan Posva
2012/11/26 18:20:13
ditto
floitsch
2012/11/28 13:44:34
Done.
|
| void add(E element) { |
| throw new UnsupportedError( |
| @@ -294,19 +290,26 @@ 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++]; |
| + // TODO(floitsch): bad error message. |
| + throw new StateError("No more elements"); |
| } |
| final List<E> _array; |