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

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

Issue 280843002: - Remove unnecessary is-check. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 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 | no next file » | 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 _GrowableList<T> implements List<T> { 5 class _GrowableList<T> implements List<T> {
6 static final int _classId = (new _GrowableList(0))._cid; 6 static final int _classId = (new _GrowableList(0))._cid;
7 7
8 void insert(int index, T element) { 8 void insert(int index, T element) {
9 if (index < 0 || index > length) { 9 if (index < 0 || index > length) {
10 throw new RangeError.range(index, 0, length); 10 throw new RangeError.range(index, 0, length);
11 } 11 }
12 if (index == this.length) { 12 if (index == this.length) {
13 add(element); 13 add(element);
14 return; 14 return;
15 } 15 }
16 int oldLength = this.length; 16 int oldLength = this.length;
17 // We are modifying the length just below the is-check. Without the check 17 // We are modifying the length just below the is-check. Without the check
18 // Array.copy could throw an exception, leaving the list in a bad state 18 // Array.copy could throw an exception, leaving the list in a bad state
19 // (with a length that has been increased, but without a new element). 19 // (with a length that has been increased, but without a new element).
20 if (index is! int) throw new ArgumentError(index); 20 if (index is! int) throw new ArgumentError(index);
21 this.length++; 21 this.length++;
22 Lists.copy(this, 22 Lists.copy(this, index, this, index + 1, oldLength - index);
23 index,
24 this,
25 index + 1,
26 oldLength - index);
27 this[index] = element; 23 this[index] = element;
28 } 24 }
29 25
30 T removeAt(int index) { 26 T removeAt(int index) {
31 if (index is! int) throw new ArgumentError(index); 27 var result = this[index];
32 T result = this[index];
33 int newLength = this.length - 1; 28 int newLength = this.length - 1;
34 Lists.copy(this, 29 Lists.copy(this, index + 1, this, index, newLength - index);
35 index + 1,
36 this,
37 index,
38 newLength - index);
39 this.length = newLength; 30 this.length = newLength;
40 return result; 31 return result;
41 } 32 }
42 33
43 bool remove(Object element) { 34 bool remove(Object element) {
44 for (int i = 0; i < this.length; i++) { 35 for (int i = 0; i < this.length; i++) {
45 if (this[i] == element) { 36 if (this[i] == element) {
46 removeAt(i); 37 removeAt(i);
47 return true; 38 return true;
48 } 39 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 Iterable<T> getRange(int start, int end) { 80 Iterable<T> getRange(int start, int end) {
90 return IterableMixinWorkaround.getRangeList(this, start, end); 81 return IterableMixinWorkaround.getRangeList(this, start, end);
91 } 82 }
92 83
93 void setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) { 84 void setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) {
94 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); 85 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount);
95 } 86 }
96 87
97 void removeRange(int start, int end) { 88 void removeRange(int start, int end) {
98 Lists.indicesCheck(this, start, end); 89 Lists.indicesCheck(this, start, end);
99 Lists.copy(this, 90 Lists.copy(this, end, this, start, this.length - end);
100 end,
101 this,
102 start,
103 this.length - end);
104 this.length = this.length - (end - start); 91 this.length = this.length - (end - start);
105 } 92 }
106 93
107 void replaceRange(int start, int end, Iterable<T> iterable) { 94 void replaceRange(int start, int end, Iterable<T> iterable) {
108 IterableMixinWorkaround.replaceRangeList(this, start, end, iterable); 95 IterableMixinWorkaround.replaceRangeList(this, start, end, iterable);
109 } 96 }
110 97
111 void fillRange(int start, int end, [T fillValue]) { 98 void fillRange(int start, int end, [T fillValue]) {
112 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); 99 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue);
113 } 100 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 340 }
354 341
355 Set<T> toSet() { 342 Set<T> toSet() {
356 return new Set<T>.from(this); 343 return new Set<T>.from(this);
357 } 344 }
358 345
359 Map<int, T> asMap() { 346 Map<int, T> asMap() {
360 return IterableMixinWorkaround.asMapList(this); 347 return IterableMixinWorkaround.asMapList(this);
361 } 348 }
362 } 349 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698