Chromium Code Reviews| Index: sdk/lib/core/queue.dart |
| diff --git a/sdk/lib/core/queue.dart b/sdk/lib/core/queue.dart |
| index 91fcfce6e4d34100b795d2ffbae76773e0dbdb6c..8b2c9673a0c586855ed7894ec5d5d0bd02919fc0 100644 |
| --- a/sdk/lib/core/queue.dart |
| +++ b/sdk/lib/core/queue.dart |
| @@ -307,7 +307,7 @@ class DoubleLinkedQueue<E> implements Queue<E> { |
| return other; |
| } |
| - _DoubleLinkedQueueIterator<E> iterator() { |
| + _DoubleLinkedQueueIterator<E> get iterator { |
| return new _DoubleLinkedQueueIterator<E>(_sentinel); |
| } |
| @@ -318,21 +318,22 @@ class DoubleLinkedQueue<E> implements Queue<E> { |
| class _DoubleLinkedQueueIterator<E> implements Iterator<E> { |
| final _DoubleLinkedQueueEntrySentinel<E> _sentinel; |
| - DoubleLinkedQueueEntry<E> _currentEntry; |
| + DoubleLinkedQueueEntry<E> _currentEntry = null; |
| - _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel this._sentinel) { |
| - _currentEntry = _sentinel; |
| - } |
| + _DoubleLinkedQueueIterator(this._sentinel); |
| - bool get hasNext { |
| - return !identical(_currentEntry._next, _sentinel); |
| + bool moveNext() { |
| + if (identical(_currentEntry, _sentinel)) return false; |
|
Lasse Reichstein Nielsen
2012/11/15 10:24:37
The 'null' represents the initial state, right?
Do
floitsch
2012/11/16 17:51:58
in theory there is no need to use identical since
|
| + if (_currentEntry == null) _currentEntry = _sentinel; |
| + _currentEntry = _currentEntry._next; |
| + return _currentEntry != _sentinel; |
| } |
| - E next() { |
| - if (!hasNext) { |
| - throw new StateError("No more elements"); |
| + E get current { |
| + if (_currentEntry != null && _currentEntry != _sentinel) { |
| + return _currentEntry.element; |
| } |
| - _currentEntry = _currentEntry._next; |
| - return _currentEntry.element; |
| + // TODO(floitsch): adapt error message. |
| + throw new StateError("No more elements"); |
| } |
| } |