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

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

Issue 2467113003: Make EfficientLength extend Iterable. (Closed)
Patch Set: Reverted, prepare to reland. Make new test not break web-testing framework. Created 4 years, 1 month 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
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | runtime/lib/immutable_map.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 _GrowableList<T> extends ListBase<T> { 5 class _GrowableList<T> extends ListBase<T> {
6 6
7 void insert(int index, T element) { 7 void insert(int index, T element) {
8 if ((index < 0) || (index > length)) { 8 if ((index < 0) || (index > length)) {
9 throw new RangeError.range(index, 0, length); 9 throw new RangeError.range(index, 0, length);
10 } 10 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 this[len] = value; 167 this[len] = value;
168 } 168 }
169 169
170 void addAll(Iterable<T> iterable) { 170 void addAll(Iterable<T> iterable) {
171 var len = length; 171 var len = length;
172 final cid = ClassID.getID(iterable); 172 final cid = ClassID.getID(iterable);
173 final isVMList = 173 final isVMList =
174 (cid == ClassID.cidArray) || 174 (cid == ClassID.cidArray) ||
175 (cid == ClassID.cidGrowableObjectArray) || 175 (cid == ClassID.cidGrowableObjectArray) ||
176 (cid == ClassID.cidImmutableArray); 176 (cid == ClassID.cidImmutableArray);
177 if (isVMList || (iterable is EfficientLength)) { 177 if (isVMList || (iterable is EfficientLengthIterable)) {
178 var cap = _capacity; 178 var cap = _capacity;
179 // Pregrow if we know iterable.length. 179 // Pregrow if we know iterable.length.
180 var iterLen = iterable.length; 180 var iterLen = iterable.length;
181 var newLen = len + iterLen; 181 var newLen = len + iterLen;
182 if (newLen > cap) { 182 if (newLen > cap) {
183 do { 183 do {
184 cap *= 2; 184 cap *= 2;
185 } while (newLen > cap); 185 } while (newLen > cap);
186 _grow(cap); 186 _grow(cap);
187 } 187 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 result._setLength(length); 360 result._setLength(length);
361 return result; 361 return result;
362 } 362 }
363 return growable ? <T>[] : new List<T>(0); 363 return growable ? <T>[] : new List<T>(0);
364 } 364 }
365 365
366 Set<T> toSet() { 366 Set<T> toSet() {
367 return new Set<T>.from(this); 367 return new Set<T>.from(this);
368 } 368 }
369 } 369 }
OLDNEW
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | runtime/lib/immutable_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698