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

Unified Diff: sdk/lib/collection/queue.dart

Issue 13685004: Reduce usage of ItearbleMixinWorkaround. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bug in set-base Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/linked_hash_set.dart ('k') | tests/corelib/iterable_min_max_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « sdk/lib/collection/linked_hash_set.dart ('k') | tests/corelib/iterable_min_max_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698