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

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: Use insertBefore and add is-check. 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
« no previous file with comments | « runtime/lib/byte_array.dart ('k') | samples/swarm/swarm_ui_lib/observable/observable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 insert(int index, T element) {
12 if (index < 0 || index > length) {
13 throw new RangeError.range(index, 0, length);
14 }
15 if (index == this.length) {
16 add(element);
17 return;
18 }
19 int oldLength = this.length;
20 // We are modifying the length just below the is-check. Without the check
21 // Array.copy could throw an exception, leaving the list in a bad state
22 // (with a length that has been increased, but without a new element).
23 if (index is! int) throw new ArgumentError(index);
24 this.length++;
25 Arrays.copy(this,
26 index,
27 this,
28 index + 1,
29 oldLength - index);
30 this[index] = element;
31 }
32
11 T removeAt(int index) { 33 T removeAt(int index) {
12 if (index is! int) throw new ArgumentError(index); 34 if (index is! int) throw new ArgumentError(index);
13 T result = this[index]; 35 T result = this[index];
14 int newLength = this.length - 1; 36 int newLength = this.length - 1;
15 Arrays.copy(this, 37 Arrays.copy(this,
16 index + 1, 38 index + 1,
17 this, 39 this,
18 index, 40 index,
19 newLength - index); 41 newLength - index);
20 this.length = newLength; 42 this.length = newLength;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 343 }
322 344
323 Set<T> toSet() { 345 Set<T> toSet() {
324 return new Set<T>.from(this); 346 return new Set<T>.from(this);
325 } 347 }
326 348
327 Map<int, T> asMap() { 349 Map<int, T> asMap() {
328 return IterableMixinWorkaround.asMapList(this); 350 return IterableMixinWorkaround.asMapList(this);
329 } 351 }
330 } 352 }
OLDNEW
« no previous file with comments | « runtime/lib/byte_array.dart ('k') | samples/swarm/swarm_ui_lib/observable/observable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698