| Index: sdk/lib/collection/queue.dart
|
| diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart
|
| index 1cacd18c18fc158784ff2fd0692a4b06e3e8a80d..c317ebb452f2f8e6b52dfd634409e0a63876b739 100644
|
| --- a/sdk/lib/collection/queue.dart
|
| +++ b/sdk/lib/collection/queue.dart
|
| @@ -9,18 +9,26 @@ part of dart.collection;
|
| * can iterate over the elements of a queue through [forEach] or with
|
| * an [Iterator].
|
| */
|
| -abstract class Queue<E> implements Iterable<E> {
|
| +abstract class Queue<E> implements Iterable<E>, EfficientLength {
|
|
|
| /**
|
| * Creates a queue.
|
| */
|
| - factory Queue() => new ListQueue<E>();
|
| + factory Queue() = ListQueue<E>;
|
|
|
| /**
|
| * Creates a queue with the elements of [other]. The order in
|
| * the queue will be the order provided by the iterator of [other].
|
| */
|
| - factory Queue.from(Iterable<E> other) => new ListQueue<E>.from(other);
|
| + factory Queue.from(Iterable<E> other) = ListQueue<E>.from;
|
| +
|
| + /**
|
| + * Returns the number of elements in the queue.
|
| + *
|
| + * This operation is efficient and does not require iterating and counting
|
| + * the elements.
|
| + */
|
| + int get length;
|
|
|
| /**
|
| * Removes and returns the first element of this queue. Throws an
|
| @@ -57,7 +65,6 @@ abstract class Queue<E> implements Iterable<E> {
|
| */
|
| bool remove(Object object);
|
|
|
| -
|
| /**
|
| * Adds all elements of [iterable] at the end of the queue. The
|
| * length of the queue is extended by the length of [iterable].
|
| @@ -304,27 +311,22 @@ class DoubleLinkedQueue<E> extends IterableBase<E> implements Queue<E> {
|
|
|
| class _DoubleLinkedQueueIterator<E> implements Iterator<E> {
|
| _DoubleLinkedQueueEntrySentinel<E> _sentinel;
|
| - DoubleLinkedQueueEntry<E> _currentEntry = null;
|
| + DoubleLinkedQueueEntry<E> _nextEntry = null;
|
| E _current;
|
|
|
| _DoubleLinkedQueueIterator(_DoubleLinkedQueueEntrySentinel<E> sentinel)
|
| - : _sentinel = sentinel, _currentEntry = sentinel;
|
| + : _sentinel = sentinel, _nextEntry = sentinel._next;
|
|
|
| bool moveNext() {
|
| // When [_currentEntry] it is set to [:null:] then it is at the end.
|
| - if (_currentEntry == null) {
|
| - assert(_current == null);
|
| - return false;
|
| + if (!identical(_nextEntry, _sentinel)) {
|
| + _current = _nextEntry._element;
|
| + _nextEntry = _nextEntry._next;
|
| + return true;
|
| }
|
| - _currentEntry = _currentEntry._next;
|
| - if (identical(_currentEntry, _sentinel)) {
|
| - _currentEntry = null;
|
| - _current = null;
|
| - _sentinel = null;
|
| - return false;
|
| - }
|
| - _current = _currentEntry.element;
|
| - return true;
|
| + _current = null;
|
| + _nextEntry = _sentinel = null; // Still identical.
|
| + return false;
|
| }
|
|
|
| E get current => _current;
|
|
|