Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 | 469 |
| 470 E removeAt(int index) { | 470 E removeAt(int index) { |
| 471 E result = this[index]; | 471 E result = this[index]; |
| 472 setRange(index, this.length - 1, this, index + 1); | 472 setRange(index, this.length - 1, this, index + 1); |
| 473 length--; | 473 length--; |
| 474 return result; | 474 return result; |
| 475 } | 475 } |
| 476 | 476 |
| 477 void insertAll(int index, Iterable<E> iterable) { | 477 void insertAll(int index, Iterable<E> iterable) { |
| 478 RangeError.checkValueInInterval(index, 0, length, "index"); | 478 RangeError.checkValueInInterval(index, 0, length, "index"); |
| 479 if (iterable is EfficientLength) { | 479 if (iterable is! EfficientLength || identical(iterable, this)) { |
|
Søren Gjesse
2015/06/01 11:37:57
Are these cased covered by tests? I guess that we
Lasse Reichstein Nielsen
2015/06/01 13:13:10
Probably not. It's hard to test because it only af
| |
| 480 iterable = iterable.toList(); | 480 iterable = iterable.toList(); |
| 481 } | 481 } |
| 482 int insertionLength = iterable.length; | 482 int insertionLength = iterable.length; |
| 483 // There might be errors after the length change, in which case the list | 483 // There might be errors after the length change, in which case the list |
| 484 // will end up being modified but the operation not complete. Unless we | 484 // will end up being modified but the operation not complete. Unless we |
| 485 // always go through a "toList" we can't really avoid that. | 485 // always go through a "toList" we can't really avoid that. |
| 486 this.length += insertionLength; | 486 this.length += insertionLength; |
| 487 if (iterable.length != insertionLength) { | |
| 488 // If the iterable's length is linked to this list's length somehow, | |
| 489 // we can't insert one in the other. | |
| 490 this.length -= insertionLength; | |
| 491 throw new ConcurrentModificationError(iterable); | |
| 492 } | |
| 487 setRange(index + insertionLength, this.length, this, index); | 493 setRange(index + insertionLength, this.length, this, index); |
| 488 setAll(index, iterable); | 494 setAll(index, iterable); |
| 489 } | 495 } |
| 490 | 496 |
| 491 void setAll(int index, Iterable<E> iterable) { | 497 void setAll(int index, Iterable<E> iterable) { |
| 492 if (iterable is List) { | 498 if (iterable is List) { |
| 493 setRange(index, index + iterable.length, iterable); | 499 setRange(index, index + iterable.length, iterable); |
| 494 } else { | 500 } else { |
| 495 for (E element in iterable) { | 501 for (E element in iterable) { |
| 496 this[index++] = element; | 502 this[index++] = element; |
| 497 } | 503 } |
| 498 } | 504 } |
| 499 } | 505 } |
| 500 | 506 |
| 501 Iterable<E> get reversed => new ReversedListIterable<E>(this); | 507 Iterable<E> get reversed => new ReversedListIterable<E>(this); |
| 502 | 508 |
| 503 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 509 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
| 504 } | 510 } |
| OLD | NEW |