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

Unified Diff: sdk/lib/collection/list.dart

Issue 13863012: Refactor List.setRange function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/collection/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index dbf3355d8901cfc77ead2ceb8a5e5eec86a58db4..818388d274684ec7c98f8001e31a6dbf3175ac65 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -277,7 +277,7 @@ abstract class ListMixin<E> implements List<E> {
void remove(Object element) {
for (int i = 0; i < this.length; i++) {
if (this[i] == element) {
- this.setRange(i, this.length - i - 1, this, i + 1);
+ this.setRange(i, i + this.length - 1, this, i + 1);
this.length -= 1;
return;
}
@@ -382,7 +382,7 @@ abstract class ListMixin<E> implements List<E> {
int moveLength = oldLength - start;
this.length += length;
if (moveLength > 0) {
- this.setRange(start + length, moveLength, this, start);
+ this.setRange(start + length, oldLength, this, start);
}
for (int i = 0; i < length; i++) {
this[start + i] = initialValue;
@@ -397,7 +397,7 @@ abstract class ListMixin<E> implements List<E> {
throw new RangeError.range(length, 0, this.length - start);
}
int end = start + length;
- setRange(start, this.length - end, this, end);
+ setRange(start, this.length - length, this, end);
this.length -= length;
}
@@ -407,16 +407,17 @@ abstract class ListMixin<E> implements List<E> {
}
}
- void setRange(int start, int length, List<E> from, [int startFrom]) {
+ void setRange(int start, int end, List<E> from, [int startFrom]) {
if (start < 0 || start > this.length) {
throw new RangeError.range(start, 0, this.length);
}
- if (length < 0 || start + length > this.length) {
- throw new RangeError.range(length, 0, this.length - start);
+ if (end < 0 || end > this.length) {
+ throw new RangeError.range(end, start, this.length);
}
if (startFrom == null) {
startFrom = 0;
}
+ int length = end - start;
if (startFrom < 0 || startFrom + length > from.length) {
throw new RangeError.range(startFrom, 0, from.length - length);
}

Powered by Google App Engine
This is Rietveld 408576698