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

Side by Side Diff: sdk/lib/collection/queue.dart

Issue 13598015: Revert 20969: Reduce usage of IterableMixinWorkaround (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
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 dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * A [Queue] is a collection that can be manipulated at both ends. One 8 * A [Queue] is a collection that can be manipulated at both ends. One
9 * can iterate over the elements of a queue through [forEach] or with 9 * can iterate over the elements of a queue through [forEach] or with
10 * an [Iterator]. 10 * an [Iterator].
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 while (!identical(entry, _sentinel)) { 217 while (!identical(entry, _sentinel)) {
218 if (entry.element == o) { 218 if (entry.element == o) {
219 entry.remove(); 219 entry.remove();
220 _elementCount--; 220 _elementCount--;
221 return; 221 return;
222 } 222 }
223 entry = entry._next; 223 entry = entry._next;
224 } 224 }
225 } 225 }
226 226
227 void retainAll(Iterable elements) { 227 void removeAll(Iterable elements) {
228 _filterIterable(elements, true); 228 // Use this method when remove is slow and removeWhere more efficient.
229 IterableMixinWorkaround.removeAllList(this, elements);
229 } 230 }
230 231
231 void removeAll(Iterable elements) { 232 void removeWhere(bool test(E element)) {
232 _filterIterable(elements, false);
233 }
234
235 void _filterIterable(Iterable elements, bool retainMatching) {
236 Set elementSet;
237 if (elements is Set) {
238 elementSet = elements;
239 } else {
240 elementSet = elements.toSet();
241 }
242 _filter(elementSet.contains, retainMatching);
243 }
244
245 void _filter(bool test(E element), bool retainMatching) {
246 DoubleLinkedQueueEntry<E> entry = firstEntry(); 233 DoubleLinkedQueueEntry<E> entry = firstEntry();
247 while (!identical(entry, _sentinel)) { 234 while (!identical(entry, _sentinel)) {
248 DoubleLinkedQueueEntry<E> next = entry._next; 235 DoubleLinkedQueueEntry<E> next = entry._next;
249 if (test(entry.element) != retainMatching) { 236 if (test(entry.element)) {
250 entry.remove(); 237 entry.remove();
251 _elementCount--; 238 _elementCount--;
252 } 239 }
253 entry = next; 240 entry = next;
254 } 241 }
255 } 242 }
256 243
257 void removeWhere(bool test(E element)) {
258 _filter(test, false);
259 }
260
261 void retainWhere(bool test(E element)) { 244 void retainWhere(bool test(E element)) {
262 _filter(test, true); 245 DoubleLinkedQueueEntry<E> entry = firstEntry();
246 while (!identical(entry, _sentinel)) {
247 DoubleLinkedQueueEntry<E> next = entry._next;
248 if (!test(entry.element)) {
249 entry.remove();
250 _elementCount--;
251 }
252 entry = next;
253 }
263 } 254 }
264 255
265 E get first { 256 E get first {
266 return _sentinel._next.element; 257 return _sentinel._next.element;
267 } 258 }
268 259
269 E get last { 260 E get last {
270 return _sentinel._previous.element; 261 return _sentinel._previous.element;
271 } 262 }
272 263
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 _queue._checkModification(_modificationCount); 707 _queue._checkModification(_modificationCount);
717 if (_position == _end) { 708 if (_position == _end) {
718 _current = null; 709 _current = null;
719 return false; 710 return false;
720 } 711 }
721 _current = _queue._table[_position]; 712 _current = _queue._table[_position];
722 _position = (_position + 1) & (_queue._table.length - 1); 713 _position = (_position + 1) & (_queue._table.length - 1);
723 return true; 714 return true;
724 } 715 }
725 } 716 }
OLDNEW
« 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