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

Unified Diff: sdk/lib/_collection_dev/iterable.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 | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index 010c8af726e13eff4754e94d15331572cca2ffde..4a031d48b62fc1e257d56d5dac298f476222c1f1 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -931,17 +931,33 @@ class IterableMixinWorkaround {
return new SubListIterable(list, start, end);
}
- static void setRangeList(List list, int start, int length,
- List from, int startFrom) {
+ static void setRangeList(List list, int start, int end,
+ Iterable from, int skipCount) {
+ if (start < 0 || start > list.length) {
+ throw new RangeError.range(start, 0, list.length);
+ }
+ if (end < start || end > list.length) {
+ throw new RangeError.range(end, start, list.length);
+ }
+ int length = end - start;
if (length == 0) return;
- if (length < 0) throw new ArgumentError(length);
- if (start < 0) throw new RangeError.value(start);
- if (start + length > list.length) {
- throw new RangeError.value(start + length);
- }
+ if (skipCount < 0) throw new ArgumentError(skipCount);
- Arrays.copy(from, startFrom, list, start, length);
+ // TODO(floitsch): Make this accept more.
+ List otherList;
+ int otherStart;
+ if (from is List) {
+ otherList = from;
+ otherStart = skipCount;
+ } else {
+ otherList = from.skip(skipCount).toList(growable: false);
+ otherStart = 0;
+ }
+ if (otherStart + length > otherList.length) {
+ throw new StateError("Not enough elements");
+ }
+ Arrays.copy(otherList, otherStart, list, start, length);
}
static Map<int, dynamic> asMapList(List l) {
« no previous file with comments | « samples/swarm/swarm_ui_lib/observable/observable.dart ('k') | sdk/lib/_collection_dev/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698