OLD | NEW |
---|---|
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) 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.
| |
13 if (index == this.length) { | |
14 add(element); | |
15 return; | |
16 } | |
17 int oldLength = this.length; | |
18 this.length++; | |
19 Arrays.copy(this, | |
20 index, | |
21 this, | |
22 index + 1, | |
23 oldLength - index); | |
24 this[index] = element; | |
25 } | |
26 | |
11 T removeAt(int index) { | 27 T removeAt(int index) { |
12 if (index is! int) throw new ArgumentError(index); | 28 if (index is! int) throw new ArgumentError(index); |
13 T result = this[index]; | 29 T result = this[index]; |
14 int newLength = this.length - 1; | 30 int newLength = this.length - 1; |
15 Arrays.copy(this, | 31 Arrays.copy(this, |
16 index + 1, | 32 index + 1, |
17 this, | 33 this, |
18 index, | 34 index, |
19 newLength - index); | 35 newLength - index); |
20 this.length = newLength; | 36 this.length = newLength; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 } | 337 } |
322 | 338 |
323 Set<T> toSet() { | 339 Set<T> toSet() { |
324 return new Set<T>.from(this); | 340 return new Set<T>.from(this); |
325 } | 341 } |
326 | 342 |
327 Map<int, T> asMap() { | 343 Map<int, T> asMap() { |
328 return IterableMixinWorkaround.asMapList(this); | 344 return IterableMixinWorkaround.asMapList(this); |
329 } | 345 } |
330 } | 346 } |
OLD | NEW |