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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/src/Serialization.dart ('k') | tools/dom/src/native_DOMImplementation.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html; 5 part of html;
6 6
7 // Iterator for arrays with fixed size. 7 // Iterator for arrays with fixed size.
8 class FixedSizeListIterator<T> extends _VariableSizeListIterator<T> { 8 class FixedSizeListIterator<T> implements Iterator<T> {
9 final List<T> _array;
10 final int _length; // Cache array length for faster access.
11 int _position;
12 T _current;
13
9 FixedSizeListIterator(List<T> array) 14 FixedSizeListIterator(List<T> array)
10 : super(array), 15 : _array = array,
16 _position = -1,
11 _length = array.length; 17 _length = array.length;
12 18
13 bool get hasNext => _length > _pos; 19 bool moveNext() {
20 int nextPosition = _position + 1;
21 if (nextPosition < _length) {
22 _current = _array[nextPosition];
23 _position = nextPosition;
24 return true;
25 }
26 _current = null;
27 _position = _length;
28 return false;
29 }
14 30
15 final int _length; // Cache array length for faster access. 31 T get current => _current;
16 } 32 }
17 33
18 // Iterator for arrays with variable size. 34 // Iterator for arrays with variable size.
19 class _VariableSizeListIterator<T> implements Iterator<T> { 35 class _VariableSizeListIterator<T> implements Iterator<T> {
36 final List<T> _array;
37 int _position;
38 T _current;
39
20 _VariableSizeListIterator(List<T> array) 40 _VariableSizeListIterator(List<T> array)
21 : _array = array, 41 : _array = array,
22 _pos = 0; 42 _position = -1;
23 43
24 bool get hasNext => _array.length > _pos; 44 bool moveNext() {
25 45 int nextPosition = _position + 1;
26 T next() { 46 if (nextPosition < _array.length) {
27 if (!hasNext) { 47 _current = _array[nextPosition];
28 throw new StateError("No more elements"); 48 _position = nextPosition;
49 return true;
29 } 50 }
30 return _array[_pos++]; 51 _current = null;
52 _position = _array.length;
53 return false;
31 } 54 }
32 55
33 final List<T> _array; 56 T get current => _current;
34 int _pos;
35 } 57 }
OLDNEW
« 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