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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 final cid = ClassID.getID(iterable); | 155 final cid = ClassID.getID(iterable); |
156 final isVMList = | 156 final isVMList = |
157 (cid == ClassID.cidArray) || | 157 (cid == ClassID.cidArray) || |
158 (cid == ClassID.cidGrowableObjectArray) || | 158 (cid == ClassID.cidGrowableObjectArray) || |
159 (cid == ClassID.cidImmutableArray); | 159 (cid == ClassID.cidImmutableArray); |
160 if (isVMList || (iterable is EfficientLength)) { | 160 if (isVMList || (iterable is EfficientLengthIterable)) { |
161 var cap = _capacity; | 161 var cap = _capacity; |
162 // Pregrow if we know iterable.length. | 162 // Pregrow if we know iterable.length. |
163 var iterLen = iterable.length; | 163 var iterLen = iterable.length; |
164 var newLen = len + iterLen; | 164 var newLen = len + iterLen; |
165 if (newLen > cap) { | 165 if (newLen > cap) { |
166 do { | 166 do { |
167 cap *= 2; | 167 cap *= 2; |
168 } while (newLen > cap); | 168 } while (newLen > cap); |
169 _grow(cap); | 169 _grow(cap); |
170 } | 170 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 result._setLength(length); | 336 result._setLength(length); |
337 return result; | 337 return result; |
338 } | 338 } |
339 return growable ? <T>[] : new List<T>(0); | 339 return growable ? <T>[] : new List<T>(0); |
340 } | 340 } |
341 | 341 |
342 Set<T> toSet() { | 342 Set<T> toSet() { |
343 return new Set<T>.from(this); | 343 return new Set<T>.from(this); |
344 } | 344 } |
345 } | 345 } |
OLD | NEW |