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

Unified Diff: tools/dom/src/_ListIterators.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months 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
« no previous file with comments | « tools/dom/src/Serialization.dart ('k') | tools/dom/src/native_DOMImplementation.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/_ListIterators.dart
diff --git a/tools/dom/src/_ListIterators.dart b/tools/dom/src/_ListIterators.dart
index 9812718eca33f584c67dc5918b8674c07e733ca1..821ef514e4bd6cec53f27ec17df5d637829bd2dd 100644
--- a/tools/dom/src/_ListIterators.dart
+++ b/tools/dom/src/_ListIterators.dart
@@ -5,31 +5,53 @@
part of html;
// Iterator for arrays with fixed size.
-class FixedSizeListIterator<T> extends _VariableSizeListIterator<T> {
+class FixedSizeListIterator<T> implements Iterator<T> {
+ final List<T> _array;
+ final int _length; // Cache array length for faster access.
+ int _position;
+ T _current;
+
FixedSizeListIterator(List<T> array)
- : super(array),
+ : _array = array,
+ _position = -1,
_length = array.length;
- bool get hasNext => _length > _pos;
+ bool moveNext() {
+ int nextPosition = _position + 1;
+ if (nextPosition < _length) {
+ _current = _array[nextPosition];
+ _position = nextPosition;
+ return true;
+ }
+ _current = null;
+ _position = _length;
+ return false;
+ }
- final int _length; // Cache array length for faster access.
+ T get current => _current;
}
// Iterator for arrays with variable size.
class _VariableSizeListIterator<T> implements Iterator<T> {
+ final List<T> _array;
+ int _position;
+ T _current;
+
_VariableSizeListIterator(List<T> array)
: _array = array,
- _pos = 0;
-
- bool get hasNext => _array.length > _pos;
-
- T next() {
- if (!hasNext) {
- throw new StateError("No more elements");
+ _position = -1;
+
+ bool moveNext() {
+ int nextPosition = _position + 1;
+ if (nextPosition < _array.length) {
+ _current = _array[nextPosition];
+ _position = nextPosition;
+ return true;
}
- return _array[_pos++];
+ _current = null;
+ _position = _array.length;
+ return false;
}
- final List<T> _array;
- int _pos;
+ T get current => _current;
}
« no previous file with comments | « tools/dom/src/Serialization.dart ('k') | tools/dom/src/native_DOMImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698