| 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 GrowableObjectArray<T> implements List<T> { | 5 class GrowableObjectArray<T> implements List<T> { |
| 6 ObjectArray<T> backingArray; | 6 ObjectArray<T> backingArray; |
| 7 | 7 |
| 8 factory GrowableObjectArray._uninstantiable() { | 8 factory GrowableObjectArray._uninstantiable() { |
| 9 throw const UnsupportedOperationException( | 9 throw const UnsupportedOperationException( |
| 10 "GrowableObjectArray can only be allocated by the VM"); | 10 "GrowableObjectArray can only be allocated by the VM"); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void grow(int capacity) { | 138 void grow(int capacity) { |
| 139 ObjectArray<T> newArray = new ObjectArray<T>(capacity); | 139 ObjectArray<T> newArray = new ObjectArray<T>(capacity); |
| 140 int length = backingArray.length; | 140 int length = backingArray.length; |
| 141 for (int i = 0; i < length; i++) { | 141 for (int i = 0; i < length; i++) { |
| 142 newArray[i] = backingArray[i]; | 142 newArray[i] = backingArray[i]; |
| 143 } | 143 } |
| 144 backingArray = newArray; | 144 backingArray = newArray; |
| 145 } | 145 } |
| 146 | 146 |
| 147 int add(T value) { | 147 void add(T value) { |
| 148 if (_length == backingArray.length) { | 148 if (_length == backingArray.length) { |
| 149 grow(_length * 2); | 149 grow(_length * 2); |
| 150 } | 150 } |
| 151 backingArray[_length] = value; | 151 backingArray[_length] = value; |
| 152 return ++_length; | 152 ++_length; |
| 153 } | 153 } |
| 154 | 154 |
| 155 void addLast(T element) { | 155 void addLast(T element) { |
| 156 add(element); | 156 add(element); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void addAll(Collection<T> collection) { | 159 void addAll(Collection<T> collection) { |
| 160 for (T elem in collection) { | 160 for (T elem in collection) { |
| 161 add(elem); | 161 add(elem); |
| 162 } | 162 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 if (!hasNext()) { | 250 if (!hasNext()) { |
| 251 throw const NoMoreElementsException(); | 251 throw const NoMoreElementsException(); |
| 252 } | 252 } |
| 253 return _array[_pos++]; | 253 return _array[_pos++]; |
| 254 } | 254 } |
| 255 | 255 |
| 256 final GrowableObjectArray<T> _array; | 256 final GrowableObjectArray<T> _array; |
| 257 int _pos; | 257 int _pos; |
| 258 } | 258 } |
| 259 | 259 |
| OLD | NEW |