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

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

Issue 873863002: Improve performance of addAll for internallt known lists. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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> 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 var len = length; 145 var len = length;
146 if (len == _capacity) { 146 if (len == _capacity) {
147 _grow(len * 2); 147 _grow(len * 2);
148 } 148 }
149 _setLength(len + 1); 149 _setLength(len + 1);
150 this[len] = value; 150 this[len] = value;
151 } 151 }
152 152
153 void addAll(Iterable<T> iterable) { 153 void addAll(Iterable<T> iterable) {
154 var len = length; 154 var len = length;
155 if (iterable is EfficientLength) { 155 final cid = ClassID.getID(iterable);
156 final isList =
Cutch 2015/01/26 20:56:38 maybe rename isBuiltinList, isVMList?
srdjan 2015/01/26 21:34:09 isVMList.
157 (cid == ClassID.cidArray) ||
158 (cid == ClassID.cidGrowableObjectArray) ||
159 (cid == ClassID.cidImmutableArray);
160 if (isList || iterable is EfficientLength) {
156 var cap = _capacity; 161 var cap = _capacity;
157 // Pregrow if we know iterable.length. 162 // Pregrow if we know iterable.length.
158 var iterLen = iterable.length; 163 var iterLen = iterable.length;
159 var newLen = len + iterLen; 164 var newLen = len + iterLen;
160 if (newLen > cap) { 165 if (newLen > cap) {
161 do { 166 do {
162 cap *= 2; 167 cap *= 2;
163 } while (newLen > cap); 168 } while (newLen > cap);
164 _grow(cap); 169 _grow(cap);
165 } 170 }
171 if (isList) {
Cutch 2015/01/26 20:56:38 Should this block (171-180) be moved down to 182?
srdjan 2015/01/26 21:34:09 This code can be executed only if isVMList is true
172 if (identical(iterable, this)) {
173 throw new ConcurrentModificationError(this);
174 }
175 this._setLength(newLen);
176 for (int i = 0; i < iterLen; i++) {
177 this[len++] = iterable[i];
178 }
179 return;
180 }
166 } 181 }
167 Iterator it = iterable.iterator; 182 Iterator it = iterable.iterator;
168 if (!it.moveNext()) return; 183 if (!it.moveNext()) return;
169 do { 184 do {
170 while (len < _capacity) { 185 while (len < _capacity) {
171 int newLen = len + 1; 186 int newLen = len + 1;
172 this._setLength(newLen); 187 this._setLength(newLen);
173 this[len] = it.current; 188 this[len] = it.current;
174 if (!it.moveNext()) return; 189 if (!it.moveNext()) return;
175 if (this.length != newLen) throw new ConcurrentModificationError(this); 190 if (this.length != newLen) throw new ConcurrentModificationError(this);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 result._setLength(length); 336 result._setLength(length);
322 return result; 337 return result;
323 } 338 }
324 return growable ? <T>[] : new List<T>(0); 339 return growable ? <T>[] : new List<T>(0);
325 } 340 }
326 341
327 Set<T> toSet() { 342 Set<T> toSet() {
328 return new Set<T>.from(this); 343 return new Set<T>.from(this);
329 } 344 }
330 } 345 }
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