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

Side by Side Diff: runtime/lib/growable_array.dart

Issue 12049065: Fix bugs in GrowableList.remove*. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Fix typo in filtered list. Created 7 years, 10 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 | « no previous file | sdk/lib/_internal/compiler/implementation/lib/js_array.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 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) { 24 void remove(Object element) {
25 for (int i = 0; i < this.length; i++) { 25 for (int i = 0; i < this.length; i++) {
26 if (this[i] == element) { 26 if (this[i] == element) {
27 int newLength = this.length - 1; 27 removeAt(i);
28 Arrays.copy(this,
29 index + 1,
30 this,
31 index,
32 newLength - index);
33 this.length = newLength;
34 return; 28 return;
35 } 29 }
36 } 30 }
37 } 31 }
38 32
33 void removeAll(Iterable elements) {
34 IterableMixinWorkaround.removeAllList(this, elements);
35 }
36
37 void retainAll(Iterable elements) {
38 IterableMixinWorkaround.retainAll(this, elements);
39 }
40
41 void removeMatching(bool test(E element)) {
42 IterableMixinWorkaround.removeMatchingList(this, test);
43 }
44
45 void retainMatching(bool test(T element)) {
46 IterableMixinWorkaround.removeMatchingList(this,
47 (T element) => !test(element));
48 }
49
39 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { 50 void setRange(int start, int length, List<T> from, [int startFrom = 0]) {
40 if (length < 0) { 51 if (length < 0) {
41 throw new ArgumentError("negative length $length"); 52 throw new ArgumentError("negative length $length");
42 } 53 }
43 Arrays.copy(from, startFrom, this, start, length); 54 Arrays.copy(from, startFrom, this, start, length);
44 } 55 }
45 56
46 void removeRange(int start, int length) { 57 void removeRange(int start, int length) {
47 if (length == 0) { 58 if (length == 0) {
48 return; 59 return;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 317 }
307 318
308 List<T> toList() { 319 List<T> toList() {
309 return new List<T>.from(this); 320 return new List<T>.from(this);
310 } 321 }
311 322
312 Set<T> toSet() { 323 Set<T> toSet() {
313 return new Set<T>.from(this); 324 return new Set<T>.from(this);
314 } 325 }
315 } 326 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/lib/js_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698