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 const UnsupportedOperationException( | 7 throw const UnsupportedOperationException( |
8 "GrowableObjectArray can only be allocated by the VM"); | 8 "GrowableObjectArray can only be allocated by the VM"); |
9 } | 9 } |
10 | 10 |
11 E removeAt(int index) { | 11 T removeAt(int index) { |
12 E result = this[index]; | 12 if (index is! int) throw new IllegalArgumentException(index); |
13 T result = this[index]; | |
13 Arrays.copy(this, | 14 Arrays.copy(this, |
kasperl
2012/09/20 12:42:41
Cache this.length in a local variable?
Lasse Reichstein Nielsen
2012/09/20 12:52:30
Better yet, I'll cache this.length - 1.
| |
14 index + 1, | 15 index + 1, |
15 this, | 16 this, |
16 index, | 17 index, |
17 this.length - index - 1); | 18 this.length - index - 1); |
18 this.length = this.length - 1; | 19 this.length = this.length - 1; |
19 return result; | 20 return result; |
20 } | 21 } |
21 | 22 |
22 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 23 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
23 if (length < 0) { | 24 if (length < 0) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 T next() { | 239 T next() { |
239 if (!hasNext()) { | 240 if (!hasNext()) { |
240 throw const NoMoreElementsException(); | 241 throw const NoMoreElementsException(); |
241 } | 242 } |
242 return _array[_pos++]; | 243 return _array[_pos++]; |
243 } | 244 } |
244 | 245 |
245 final GrowableObjectArray<T> _array; | 246 final GrowableObjectArray<T> _array; |
246 int _pos; | 247 int _pos; |
247 } | 248 } |
OLD | NEW |