| // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| // for details. All rights reserved. Use of this source code is governed by a | |
| // BSD-style license that can be found in the LICENSE file. | |
| part of html; | |
| // Iterator for arrays with fixed size. | |
| 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) | |
| : _array = array, | |
| _position = -1, | |
| _length = array.length; | |
| bool moveNext() { | |
| int nextPosition = _position + 1; | |
| if (nextPosition < _length) { | |
| _current = _array[nextPosition]; | |
| _position = nextPosition; | |
| return true; | |
| } | |
| _current = null; | |
| _position = _length; | |
| return false; | |
| } | |
| T get current => _current as T; | |
| } | |
| // 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, | |
| _position = -1; | |
| bool moveNext() { | |
| int nextPosition = _position + 1; | |
| if (nextPosition < _array.length) { | |
| _current = _array[nextPosition]; | |
| _position = nextPosition; | |
| return true; | |
| } | |
| _current = null; | |
| _position = _array.length; | |
| return false; | |
| } | |
| T get current => _current as T; | |
| } |