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

Unified Diff: runtime/lib/array.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
« no previous file with comments | « no previous file | runtime/lib/byte_array.dart » ('j') | sdk/lib/collection/collections.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | runtime/lib/byte_array.dart » ('j') | sdk/lib/collection/collections.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698