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

Unified Diff: runtime/lib/growable_array.dart

Issue 14175013: Add setAll, insertAll, replaceRange and fillRange. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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: runtime/lib/growable_array.dart
diff --git a/runtime/lib/growable_array.dart b/runtime/lib/growable_array.dart
index d19cc2f9df873fe0480058dd424ea2eecaee63b8..f24da18e521f060e2421533aec40f1b64b2e0706 100644
--- a/runtime/lib/growable_array.dart
+++ b/runtime/lib/growable_array.dart
@@ -52,6 +52,33 @@ class _GrowableObjectArray<T> implements List<T> {
}
}
+ void insertAll(int index, Iterable<T> iterable) {
+ if (index < 0 || index > length) {
+ throw new RangeError.range(index, 0, length);
+ }
+ // TODO(floitsch): we can probably detect more cases.
+ if (iterable is! List && iterable is! Set && iterable is! SubListIterable) {
+ iterable = iterable.toList();
+ }
+ int insertionLength = iterable.length;
+ // There might be errors after the length change, in which case the list
+ // will end up being modified but the operation not complete. Unless we
+ // always go through a "toList" we can't really avoid that.
+ this.length += insertionLength;
+ setRange(index + insertionLength, this.length, this, index);
+ setAll(index, iterable);
+ }
+
+ void setAll(int index, Iterable<T> iterable) {
+ if (iterable is List) {
+ setRange(index, index + iterable.length, iterable);
Lasse Reichstein Nielsen 2013/04/15 12:11:31 Notice how the other parameter structure for setRa
+ } else {
+ for (T element in iterable) {
+ this[index++] = element;
+ }
+ }
+ }
+
void removeWhere(bool test(T element)) {
IterableMixinWorkaround.removeWhereList(this, test);
}
@@ -79,6 +106,14 @@ class _GrowableObjectArray<T> implements List<T> {
this.length = this.length - (end - start);
}
+ void replaceRange(int start, int end, Iterable<T> iterable) {
+ IterableMixinWorkaround.replaceRangeList(this, start, end, iterable);
+ }
+
+ void fillRange(int start, int end, [T fillValue]) {
+ IterableMixinWorkaround.fillRangeList(this, start, end, fillValue);
+ }
+
List<T> sublist(int start, [int end]) {
Arrays.indicesCheck(this, start, end);
if (end == null) end = length;

Powered by Google App Engine
This is Rietveld 408576698