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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _GrowableObjectArray<T> implements List<T> { 5 class _GrowableObjectArray<T> implements List<T> {
6 factory _GrowableObjectArray._uninstantiable() { 6 factory _GrowableObjectArray._uninstantiable() {
7 throw new UnsupportedError( 7 throw new UnsupportedError(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
11 void insertAt(int index, T element) {
12 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.
13 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.
14 int newLength = this.length + 1;
15 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.
16 Arrays.copy(this,
17 index,
18 this,
19 index + 1,
20 newLength - index - 1);
21 this[index] = element;
22 }
23
11 T removeAt(int index) { 24 T removeAt(int index) {
12 if (index is! int) throw new ArgumentError(index); 25 if (index is! int) throw new ArgumentError(index);
13 T result = this[index]; 26 T result = this[index];
14 int newLength = this.length - 1; 27 int newLength = this.length - 1;
15 Arrays.copy(this, 28 Arrays.copy(this,
16 index + 1, 29 index + 1,
17 this, 30 this,
18 index, 31 index,
19 newLength - index); 32 newLength - index);
20 this.length = newLength; 33 this.length = newLength;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 334 }
322 335
323 List<T> toList({ bool growable: false }) { 336 List<T> toList({ bool growable: false }) {
324 return new List<T>.from(this, growable: growable); 337 return new List<T>.from(this, growable: growable);
325 } 338 }
326 339
327 Set<T> toSet() { 340 Set<T> toSet() {
328 return new Set<T>.from(this); 341 return new Set<T>.from(this);
329 } 342 }
330 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698