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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.dev; 5 part of dart._collection.dev;
6 6
7 /** 7 /**
8 * An [Iterable] for classes that have efficient [length] and [elementAt]. 8 * An [Iterable] for classes that have efficient [length] and [elementAt].
9 * 9 *
10 * All other methods are implemented in terms of [length] and [elementAt], 10 * All other methods are implemented in terms of [length] and [elementAt],
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 if (start < 0 || start > list.length) { 924 if (start < 0 || start > list.length) {
925 throw new RangeError.range(start, 0, list.length); 925 throw new RangeError.range(start, 0, list.length);
926 } 926 }
927 if (end < start || end > list.length) { 927 if (end < start || end > list.length) {
928 throw new RangeError.range(end, start, list.length); 928 throw new RangeError.range(end, start, list.length);
929 } 929 }
930 // The generic type is currently lost. It will be fixed with mixins. 930 // The generic type is currently lost. It will be fixed with mixins.
931 return new SubListIterable(list, start, end); 931 return new SubListIterable(list, start, end);
932 } 932 }
933 933
934 static void setRangeList(List list, int start, int length, 934 static void setRangeList(List list, int start, int end,
935 List from, int startFrom) { 935 Iterable from, int skipCount) {
936 if (start < 0 || start > list.length) {
937 throw new RangeError.range(start, 0, list.length);
938 }
939 if (end < start || end > list.length) {
940 throw new RangeError.range(end, start, list.length);
941 }
942 int length = end - start;
936 if (length == 0) return; 943 if (length == 0) return;
937 944
938 if (length < 0) throw new ArgumentError(length); 945 if (skipCount < 0) throw new ArgumentError(skipCount);
939 if (start < 0) throw new RangeError.value(start); 946
940 if (start + length > list.length) { 947 // TODO(floitsch): Make this accept more.
941 throw new RangeError.value(start + length); 948 List otherList;
949 int otherStart;
950 if (from is List) {
951 otherList = from;
952 otherStart = skipCount;
953 } else {
954 otherList = from.skip(skipCount).toList(growable: false);
955 otherStart = 0;
942 } 956 }
943 957 if (otherStart + length > otherList.length) {
944 Arrays.copy(from, startFrom, list, start, length); 958 throw new StateError("Not enough elements");
959 }
960 Arrays.copy(otherList, otherStart, list, start, length);
945 } 961 }
946 962
947 static Map<int, dynamic> asMapList(List l) { 963 static Map<int, dynamic> asMapList(List l) {
948 return new ListMapView(l); 964 return new ListMapView(l);
949 } 965 }
950 966
951 static bool setContainsAll(Set set, Iterable other) { 967 static bool setContainsAll(Set set, Iterable other) {
952 for (var element in other) { 968 for (var element in other) {
953 if (!set.contains(element)) return false; 969 if (!set.contains(element)) return false;
954 } 970 }
(...skipping 26 matching lines...) Expand all
981 997
982 static Set setDifference(Set set, Set other, Set result) { 998 static Set setDifference(Set set, Set other, Set result) {
983 for (var element in set) { 999 for (var element in set) {
984 if (!other.contains(element)) { 1000 if (!other.contains(element)) {
985 result.add(element); 1001 result.add(element);
986 } 1002 }
987 } 1003 }
988 return result; 1004 return result;
989 } 1005 }
990 } 1006 }
OLDNEW
« 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