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

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

Issue 2698353003: unfork DDC's copy of most SDK libraries (Closed)
Patch Set: revert core_patch Created 3 years, 10 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
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 * Abstract implementation of a list. 8 * Abstract implementation of a list.
9 * 9 *
10 * `ListBase` can be used as a base class for implementing the `List` interface. 10 * `ListBase` can be used as a base class for implementing the `List` interface.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 267 }
268 268
269 void removeWhere(bool test(E element)) { 269 void removeWhere(bool test(E element)) {
270 _filter(this, test, false); 270 _filter(this, test, false);
271 } 271 }
272 272
273 void retainWhere(bool test(E element)) { 273 void retainWhere(bool test(E element)) {
274 _filter(this, test, true); 274 _filter(this, test, true);
275 } 275 }
276 276
277 static void _filter(List source, 277 void _filter(List source, bool test(var element), bool retainMatching) {
Lasse Reichstein Nielsen 2017/02/28 14:55:05 Now that this is no longer a static method, the fi
Jennifer Messerly 2017/02/28 23:46:16 ah good catch! I made this fix over at: https://co
278 bool test(var element), 278 List<E> retained = <E>[];
279 bool retainMatching) {
280 List retained = [];
281 int length = source.length; 279 int length = source.length;
282 for (int i = 0; i < length; i++) { 280 for (int i = 0; i < length; i++) {
283 var element = source[i]; 281 var element = source[i];
284 if (test(element) == retainMatching) { 282 if (test(element) == retainMatching) {
285 retained.add(element); 283 retained.add(element);
286 } 284 }
287 if (length != source.length) { 285 if (length != source.length) {
288 throw new ConcurrentModificationError(source); 286 throw new ConcurrentModificationError(source);
289 } 287 }
290 } 288 }
(...skipping 11 matching lines...) Expand all
302 if (length == 0) { 300 if (length == 0) {
303 throw IterableElementError.noElement(); 301 throw IterableElementError.noElement();
304 } 302 }
305 E result = this[length - 1]; 303 E result = this[length - 1];
306 length--; 304 length--;
307 return result; 305 return result;
308 } 306 }
309 307
310 void sort([int compare(E a, E b)]) { 308 void sort([int compare(E a, E b)]) {
311 if (compare == null) { 309 if (compare == null) {
312 Sort.sort(this, Comparable.compare); 310 Sort.sort(this, (a, b) => Comparable.compare(a, b));
313 } else { 311 } else {
314 Sort.sort(this, compare); 312 Sort.sort(this, compare);
315 } 313 }
316 } 314 }
317 315
318 void shuffle([Random random]) { 316 void shuffle([Random random]) {
319 if (random == null) random = new Random(); 317 if (random == null) random = new Random();
320 int length = this.length; 318 int length = this.length;
321 while (length > 1) { 319 while (length > 1) {
322 int pos = random.nextInt(length); 320 int pos = random.nextInt(length);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 for (E element in iterable) { 505 for (E element in iterable) {
508 this[index++] = element; 506 this[index++] = element;
509 } 507 }
510 } 508 }
511 } 509 }
512 510
513 Iterable<E> get reversed => new ReversedListIterable<E>(this); 511 Iterable<E> get reversed => new ReversedListIterable<E>(this);
514 512
515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); 513 String toString() => IterableBase.iterableToFullString(this, '[', ']');
516 } 514 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698