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

Unified Diff: runtime/lib/array.dart

Issue 13863012: Refactor List.setRange function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. 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
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | runtime/lib/function_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/array.dart
diff --git a/runtime/lib/array.dart b/runtime/lib/array.dart
index 0ee4d081058a604b9d51d7dab38d7cfef9ce3bad..1aa5bba291223623fb93e14287aabc842d901ee2 100644
--- a/runtime/lib/array.dart
+++ b/runtime/lib/array.dart
@@ -54,14 +54,30 @@ class _ObjectArray<E> implements List<E> {
}
// List interface.
- void setRange(int start, int length, List<E> from, [int startFrom = 0]) {
- if (length < 0) {
- throw new ArgumentError("negative length $length");
+ void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
+ if (start < 0 || start > this.length) {
+ throw new RangeError.range(start, 0, this.length);
}
- if (from is _ObjectArray) {
- _copyFromObjectArray(from, startFrom, start, length);
+ if (end < 0 || end > this.length) {
+ throw new RangeError.range(end, start, this.length);
+ }
+ int length = end - start;
+ if (length == 0) return;
+
+ if (iterable is _ObjectArray) {
+ _copyFromObjectArray(iterable, skipCount, start, length);
} else {
- Arrays.copy(from, startFrom, this, start, length);
+ List otherList;
+ int otherStart;
+ if (iterable is List) {
+ otherList = iterable;
+ otherStart = skipCount;
+ } else {
+ otherList =
+ iterable.skip(skipCount).take(length).toList(growable: false);
+ otherStart = 0;
+ }
+ Arrays.copy(otherList, otherStart, this, start, length);
}
}
@@ -292,7 +308,7 @@ class _ImmutableArray<E> implements List<E> {
"Cannot modify an immutable array");
}
- void setRange(int start, int length, List<E> from, [int startFrom = 0]) {
+ void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
throw new UnsupportedError(
"Cannot modify an immutable array");
}
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | runtime/lib/function_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698