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> 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); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 Lists.indicesCheck(this, start, end); | 103 Lists.indicesCheck(this, start, end); |
104 if (end == null) end = this.length; | 104 if (end == null) end = this.length; |
105 int length = end - start; | 105 int length = end - start; |
106 if (start == end) return <T>[]; | 106 if (start == end) return <T>[]; |
107 List list = new _GrowableList<T>.withCapacity(length); | 107 List list = new _GrowableList<T>.withCapacity(length); |
108 list.length = length; | 108 list.length = length; |
109 Lists.copy(this, start, list, 0, length); | 109 Lists.copy(this, start, list, 0, length); |
110 return list; | 110 return list; |
111 } | 111 } |
112 | 112 |
| 113 static final int _kDefaultCapacity = 2; |
| 114 |
113 factory _GrowableList(int length) { | 115 factory _GrowableList(int length) { |
114 var data = new _List((length == 0) ? 4 : length); | 116 var data = new _List((length == 0) ? _kDefaultCapacity : length); |
115 var result = new _GrowableList<T>.withData(data); | 117 var result = new _GrowableList<T>.withData(data); |
116 if (length > 0) { | 118 if (length > 0) { |
117 result._setLength(length); | 119 result._setLength(length); |
118 } | 120 } |
119 return result; | 121 return result; |
120 } | 122 } |
121 | 123 |
122 factory _GrowableList.withCapacity(int capacity) { | 124 factory _GrowableList.withCapacity(int capacity) { |
123 var data = new _List((capacity == 0)? 4 : capacity); | 125 var data = new _List((capacity == 0)? _kDefaultCapacity : capacity); |
124 return new _GrowableList<T>.withData(data); | 126 return new _GrowableList<T>.withData(data); |
125 } | 127 } |
126 | 128 |
127 factory _GrowableList.from(Iterable<T> other) { | 129 factory _GrowableList.from(Iterable<T> other) { |
128 List<T> result = new _GrowableList<T>(); | 130 List<T> result = new _GrowableList<T>(); |
129 result.addAll(other); | 131 result.addAll(other); |
130 return result; | 132 return result; |
131 } | 133 } |
132 | 134 |
133 factory _GrowableList.withData(_List data) | 135 factory _GrowableList.withData(_List data) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 340 } |
339 | 341 |
340 Set<T> toSet() { | 342 Set<T> toSet() { |
341 return new Set<T>.from(this); | 343 return new Set<T>.from(this); |
342 } | 344 } |
343 | 345 |
344 Map<int, T> asMap() { | 346 Map<int, T> asMap() { |
345 return IterableMixinWorkaround.asMapList(this); | 347 return IterableMixinWorkaround.asMapList(this); |
346 } | 348 } |
347 } | 349 } |
OLD | NEW |