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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 149 } |
150 | 150 |
151 void _setLength(int new_length) native "GrowableList_setLength"; | 151 void _setLength(int new_length) native "GrowableList_setLength"; |
152 | 152 |
153 void _setData(_List array) native "GrowableList_setData"; | 153 void _setData(_List array) native "GrowableList_setData"; |
154 | 154 |
155 T operator [](int index) native "GrowableList_getIndexed"; | 155 T operator [](int index) native "GrowableList_getIndexed"; |
156 | 156 |
157 void operator []=(int index, T value) native "GrowableList_setIndexed"; | 157 void operator []=(int index, T value) native "GrowableList_setIndexed"; |
158 | 158 |
| 159 void set last(T value) { |
| 160 if (length == 0) throw IterableElementError.noElement(); |
| 161 this[length - 1] = value; |
| 162 } |
| 163 |
159 // The length of this growable array. It is always less than or equal to the | 164 // The length of this growable array. It is always less than or equal to the |
160 // length of the object array, which itself is always greater than 0, so that | 165 // length of the object array, which itself is always greater than 0, so that |
161 // grow() does not have to check for a zero length object array before | 166 // grow() does not have to check for a zero length object array before |
162 // doubling its size. | 167 // doubling its size. |
163 void add(T value) { | 168 void add(T value) { |
164 var len = length; | 169 var len = length; |
165 if (len == _capacity) { | 170 if (len == _capacity) { |
166 _grow(len * 2); | 171 _grow(len * 2); |
167 } | 172 } |
168 _setLength(len + 1); | 173 _setLength(len + 1); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 343 } |
339 | 344 |
340 Set<T> toSet() { | 345 Set<T> toSet() { |
341 return new Set<T>.from(this); | 346 return new Set<T>.from(this); |
342 } | 347 } |
343 | 348 |
344 Map<int, T> asMap() { | 349 Map<int, T> asMap() { |
345 return IterableMixinWorkaround.asMapList(this); | 350 return IterableMixinWorkaround.asMapList(this); |
346 } | 351 } |
347 } | 352 } |
OLD | NEW |