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

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: Created 7 years, 10 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 e1a858364b035e1c726ecd26c9da234cfeb3f1be..bdfe19cfe88e3f51d1c12419d221bdba3a93d396 100644
--- a/runtime/lib/growable_array.dart
+++ b/runtime/lib/growable_array.dart
@@ -8,6 +8,19 @@ class _GrowableObjectArray<T> implements List<T> {
"GrowableObjectArray can only be allocated by the VM");
}
+ void insertAt(int index, T element) {
+ if (index is! int) throw new ArgumentError(index);
srdjan 2013/03/04 00:53:47 Per Lars's instructions no explicit type checks sh
floitsch 2013/03/05 17:51:58 Done.
+ if (index < 0 || index > length) throw new RangeError(index);
Lasse Reichstein Nielsen 2013/03/04 09:06:02 Consider special-casing index == length into 'add'
floitsch 2013/03/05 17:51:58 Done.
+ int newLength = this.length + 1;
+ this.length = newLength;
srdjan 2013/03/04 00:53:47 Why not just 'this.length+= 1;'?
Lasse Reichstein Nielsen 2013/03/04 09:06:02 Remember oldLength instead. It seems it's what you
floitsch 2013/03/05 17:51:58 Done.
+ Arrays.copy(this,
+ index,
+ this,
+ index + 1,
+ newLength - index - 1);
+ 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