Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Unified Diff: sdk/lib/core/queue.dart

Issue 11410086: Use iterator, moveNext(), current. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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");
}
}

Powered by Google App Engine
This is Rietveld 408576698