| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 */ | 191 */ |
| 192 | 192 |
| 193 void forEach(f(T element)) { | 193 void forEach(f(T element)) { |
| 194 // TODO(srdjan): Use Collections.forEach(this, f); | 194 // TODO(srdjan): Use Collections.forEach(this, f); |
| 195 // Using backingArray directly improves DeltaBlue performance by 25%. | 195 // Using backingArray directly improves DeltaBlue performance by 25%. |
| 196 for (int i = 0; i < _length; i++) { | 196 for (int i = 0; i < _length; i++) { |
| 197 f(backingArray[i]); | 197 f(backingArray[i]); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 Collection map(f(T element)) { |
| 202 return Collections.map(this, new GrowableObjectArray.withCapacity(length), f
); |
| 203 } |
| 204 |
| 201 Collection<T> filter(bool f(T element)) { | 205 Collection<T> filter(bool f(T element)) { |
| 202 return Collections.filter(this, new GrowableObjectArray<T>(), f); | 206 return Collections.filter(this, new GrowableObjectArray<T>(), f); |
| 203 } | 207 } |
| 204 | 208 |
| 205 bool every(bool f(T element)) { | 209 bool every(bool f(T element)) { |
| 206 return Collections.every(this, f); | 210 return Collections.every(this, f); |
| 207 } | 211 } |
| 208 | 212 |
| 209 bool some(bool f(T element)) { | 213 bool some(bool f(T element)) { |
| 210 return Collections.some(this, f); | 214 return Collections.some(this, f); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 if (!hasNext()) { | 250 if (!hasNext()) { |
| 247 throw const NoMoreElementsException(); | 251 throw const NoMoreElementsException(); |
| 248 } | 252 } |
| 249 return _array[_pos++]; | 253 return _array[_pos++]; |
| 250 } | 254 } |
| 251 | 255 |
| 252 final GrowableObjectArray<T> _array; | 256 final GrowableObjectArray<T> _array; |
| 253 int _pos; | 257 int _pos; |
| 254 } | 258 } |
| 255 | 259 |
| OLD | NEW |