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

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

Issue 2467113003: Make EfficientLength extend Iterable. (Closed)
Patch Set: Reverted, prepare to reland. Make new test not break web-testing framework. Created 4 years, 1 month 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/collection/iterable.dart ('k') | sdk/lib/collection/maps.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) 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 388 }
389 } else { 389 } else {
390 for (int i = 0; i < length; i++) { 390 for (int i = 0; i < length; i++) {
391 this[start + i] = otherList[otherStart + i]; 391 this[start + i] = otherList[otherStart + i];
392 } 392 }
393 } 393 }
394 } 394 }
395 395
396 void replaceRange(int start, int end, Iterable<E> newContents) { 396 void replaceRange(int start, int end, Iterable<E> newContents) {
397 RangeError.checkValidRange(start, end, this.length); 397 RangeError.checkValidRange(start, end, this.length);
398 if (newContents is! EfficientLength) { 398 if (newContents is! EfficientLengthIterable) {
399 newContents = newContents.toList(); 399 newContents = newContents.toList();
400 } 400 }
401 int removeLength = end - start; 401 int removeLength = end - start;
402 int insertLength = newContents.length; 402 int insertLength = newContents.length;
403 if (removeLength >= insertLength) { 403 if (removeLength >= insertLength) {
404 int delta = removeLength - insertLength; 404 int delta = removeLength - insertLength;
405 int insertEnd = start + insertLength; 405 int insertEnd = start + insertLength;
406 int newLength = this.length - delta; 406 int newLength = this.length - delta;
407 this.setRange(start, insertEnd, newContents); 407 this.setRange(start, insertEnd, newContents);
408 if (delta != 0) { 408 if (delta != 0) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 475
476 E removeAt(int index) { 476 E removeAt(int index) {
477 E result = this[index]; 477 E result = this[index];
478 setRange(index, this.length - 1, this, index + 1); 478 setRange(index, this.length - 1, this, index + 1);
479 length--; 479 length--;
480 return result; 480 return result;
481 } 481 }
482 482
483 void insertAll(int index, Iterable<E> iterable) { 483 void insertAll(int index, Iterable<E> iterable) {
484 RangeError.checkValueInInterval(index, 0, length, "index"); 484 RangeError.checkValueInInterval(index, 0, length, "index");
485 if (iterable is! EfficientLength || identical(iterable, this)) { 485 if (iterable is! EfficientLengthIterable || identical(iterable, this)) {
486 iterable = iterable.toList(); 486 iterable = iterable.toList();
487 } 487 }
488 int insertionLength = iterable.length; 488 int insertionLength = iterable.length;
489 // There might be errors after the length change, in which case the list 489 // There might be errors after the length change, in which case the list
490 // will end up being modified but the operation not complete. Unless we 490 // will end up being modified but the operation not complete. Unless we
491 // always go through a "toList" we can't really avoid that. 491 // always go through a "toList" we can't really avoid that.
492 this.length += insertionLength; 492 this.length += insertionLength;
493 if (iterable.length != insertionLength) { 493 if (iterable.length != insertionLength) {
494 // If the iterable's length is linked to this list's length somehow, 494 // If the iterable's length is linked to this list's length somehow,
495 // we can't insert one in the other. 495 // we can't insert one in the other.
(...skipping 11 matching lines...) Expand all
507 for (E element in iterable) { 507 for (E element in iterable) {
508 this[index++] = element; 508 this[index++] = element;
509 } 509 }
510 } 510 }
511 } 511 }
512 512
513 Iterable<E> get reversed => new ReversedListIterable<E>(this); 513 Iterable<E> get reversed => new ReversedListIterable<E>(this);
514 514
515 String toString() => IterableBase.iterableToFullString(this, '[', ']'); 515 String toString() => IterableBase.iterableToFullString(this, '[', ']');
516 } 516 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/iterable.dart ('k') | sdk/lib/collection/maps.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698