Index: sdk/lib/collection/queue.dart |
diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart |
index c6cca9f8b8057208a98507d71ca3bd5b035c5b76..c5d5d367ea67d876ce5f4aed0af2a3eb1d9e3c8e 100644 |
--- a/sdk/lib/collection/queue.dart |
+++ b/sdk/lib/collection/queue.dart |
@@ -224,28 +224,29 @@ class DoubleLinkedQueue<E> extends Collection<E> implements Queue<E> { |
} |
} |
+ void retainAll(Iterable elements) { |
+ _filterIterable(elements, true); |
+ } |
+ |
void removeAll(Iterable elements) { |
- // Use this method when remove is slow and removeWhere more efficient. |
- IterableMixinWorkaround.removeAllList(this, elements); |
+ _filterIterable(elements, false); |
} |
- void removeWhere(bool test(E element)) { |
- DoubleLinkedQueueEntry<E> entry = firstEntry(); |
- while (!identical(entry, _sentinel)) { |
- DoubleLinkedQueueEntry<E> next = entry._next; |
- if (test(entry.element)) { |
- entry.remove(); |
- _elementCount--; |
- } |
- entry = next; |
+ void _filterIterable(Iterable elements, bool retainMatching) { |
+ Set elementSet; |
+ if (elements is Set) { |
+ elementSet = elements; |
+ } else { |
+ elementSet = elements.toSet(); |
} |
+ _filter(elementSet.contains, retainMatching); |
} |
- void retainWhere(bool test(E element)) { |
+ void _filter(bool test(E element), bool retainMatching) { |
DoubleLinkedQueueEntry<E> entry = firstEntry(); |
while (!identical(entry, _sentinel)) { |
DoubleLinkedQueueEntry<E> next = entry._next; |
- if (!test(entry.element)) { |
+ if (test(entry.element) != retainMatching) { |
entry.remove(); |
_elementCount--; |
} |
@@ -253,6 +254,14 @@ class DoubleLinkedQueue<E> extends Collection<E> implements Queue<E> { |
} |
} |
+ void removeWhere(bool test(E element)) { |
+ _filter(test, false); |
+ } |
+ |
+ void retainWhere(bool test(E element)) { |
+ _filter(test, true); |
+ } |
+ |
E get first { |
return _sentinel._next.element; |
} |