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 T removeAt(int index) { | 11 T removeAt(int index) { |
12 if (index is! int) throw new ArgumentError(index); | 12 if (index is! int) throw new ArgumentError(index); |
13 T result = this[index]; | 13 T result = this[index]; |
14 int newLength = this.length - 1; | 14 int newLength = this.length - 1; |
15 Arrays.copy(this, | 15 Arrays.copy(this, |
16 index + 1, | 16 index + 1, |
17 this, | 17 this, |
18 index, | 18 index, |
19 newLength - index); | 19 newLength - index); |
20 this.length = newLength; | 20 this.length = newLength; |
21 return result; | 21 return result; |
22 } | 22 } |
23 | 23 |
| 24 void remove(Object element) { |
| 25 for (int i = 0; i < this.length; i++) { |
| 26 if (this[i] == element) { |
| 27 int newLength = this.length - 1; |
| 28 Arrays.copy(this, |
| 29 index + 1, |
| 30 this, |
| 31 index, |
| 32 newLength - index); |
| 33 this.length = newLength; |
| 34 return; |
| 35 } |
| 36 } |
| 37 } |
| 38 |
24 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 39 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
25 if (length < 0) { | 40 if (length < 0) { |
26 throw new ArgumentError("negative length $length"); | 41 throw new ArgumentError("negative length $length"); |
27 } | 42 } |
28 Arrays.copy(from, startFrom, this, start, length); | 43 Arrays.copy(from, startFrom, this, start, length); |
29 } | 44 } |
30 | 45 |
31 void removeRange(int start, int length) { | 46 void removeRange(int start, int length) { |
32 if (length == 0) { | 47 if (length == 0) { |
33 return; | 48 return; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 305 } |
291 | 306 |
292 List<T> toList() { | 307 List<T> toList() { |
293 return new List<T>.from(this); | 308 return new List<T>.from(this); |
294 } | 309 } |
295 | 310 |
296 Set<T> toSet() { | 311 Set<T> toSet() { |
297 return new Set<T>.from(this); | 312 return new Set<T>.from(this); |
298 } | 313 } |
299 } | 314 } |
OLD | NEW |