| Index: sdk/lib/collection/list.dart
|
| diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
|
| index 92b1110b192500795207b14ccb9491d57c7b696c..7f476dc9aa2023de4b9aceb1a924dc3584eee15c 100644
|
| --- a/sdk/lib/collection/list.dart
|
| +++ b/sdk/lib/collection/list.dart
|
| @@ -256,27 +256,14 @@ abstract class ListMixin<E> implements List<E> {
|
| bool remove(Object element) {
|
| for (int i = 0; i < this.length; i++) {
|
| if (this[i] == element) {
|
| - this._closeGap(i, i + 1);
|
| + this.setRange(i, this.length - 1, this, i + 1);
|
| + this.length -= 1;
|
| return true;
|
| }
|
| }
|
| return false;
|
| }
|
|
|
| - /// Removes elements from the list starting at [start] up to but not including
|
| - /// [end]. Arguments are pre-validated.
|
| - void _closeGap(int start, int end) {
|
| - int length = this.length;
|
| - assert(0 <= start);
|
| - assert(start < end);
|
| - assert(end <= length);
|
| - int size = end - start;
|
| - for (int i = end; i < length; i++) {
|
| - this[i - size] = this[i];
|
| - }
|
| - this.length = length - size;
|
| - }
|
| -
|
| void removeWhere(bool test(E element)) {
|
| _filter(test, false);
|
| }
|
| @@ -363,9 +350,9 @@ abstract class ListMixin<E> implements List<E> {
|
|
|
| void removeRange(int start, int end) {
|
| RangeError.checkValidRange(start, end, this.length);
|
| - if (end > start) {
|
| - _closeGap(start, end);
|
| - }
|
| + int length = end - start;
|
| + setRange(start, this.length - length, this, end);
|
| + this.length -= length;
|
| }
|
|
|
| void fillRange(int start, int end, [E fill]) {
|
| @@ -414,10 +401,13 @@ abstract class ListMixin<E> implements List<E> {
|
| int removeLength = end - start;
|
| int insertLength = newContents.length;
|
| if (removeLength >= insertLength) {
|
| + int delta = removeLength - insertLength;
|
| int insertEnd = start + insertLength;
|
| + int newLength = this.length - delta;
|
| this.setRange(start, insertEnd, newContents);
|
| - if (removeLength > insertLength) {
|
| - _closeGap(insertEnd, end);
|
| + if (delta != 0) {
|
| + this.setRange(insertEnd, newLength, this, end);
|
| + this.length = newLength;
|
| }
|
| } else {
|
| int delta = insertLength - removeLength;
|
| @@ -480,7 +470,8 @@ abstract class ListMixin<E> implements List<E> {
|
|
|
| E removeAt(int index) {
|
| E result = this[index];
|
| - _closeGap(index, index + 1);
|
| + setRange(index, this.length - 1, this, index + 1);
|
| + length--;
|
| return result;
|
| }
|
|
|
|
|