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

Unified Diff: runtime/lib/growable_array.dart

Issue 12383073: Add List.insert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename insertAt to insert.~ Created 7 years, 9 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 5759178e8609c68362b633b77af9dbea899808bf..3b5adc46bbd270dd79eaad0c0f6aa153d599f0da 100644
--- a/runtime/lib/growable_array.dart
+++ b/runtime/lib/growable_array.dart
@@ -8,6 +8,22 @@ class _GrowableObjectArray<T> implements List<T> {
"GrowableObjectArray can only be allocated by the VM");
}
+ void insert(int index, T element) {
+ if (index < 0 || index > length) throw new RangeError(index);
Lasse Reichstein Nielsen 2013/03/07 09:57:53 new RangeError.range(index, 0, length)
floitsch 2013/03/07 12:53:53 Done.
+ if (index == this.length) {
+ add(element);
+ return;
+ }
+ int oldLength = this.length;
+ this.length++;
+ Arrays.copy(this,
+ index,
+ this,
+ index + 1,
+ oldLength - index);
+ this[index] = element;
+ }
+
T removeAt(int index) {
if (index is! int) throw new ArgumentError(index);
T result = this[index];

Powered by Google App Engine
This is Rietveld 408576698