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 _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 Loading... |
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 EfficientLengthIterable)) { | 177 if (isVMList || (iterable is EfficientLength)) { |
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 Loading... |
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 } |
OLD | NEW |