| 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 | 5 |
| 6 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
| 7 class _ObjectArray<E> implements List<E> { | 7 class _ObjectArray<E> implements List<E> { |
| 8 | 8 |
| 9 factory _ObjectArray(int length) native "ObjectArray_allocate"; | 9 factory _ObjectArray(int length) native "ObjectArray_allocate"; |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 List<E> getRange(int start, int length) { | 53 List<E> getRange(int start, int length) { |
| 54 if (length == 0) return []; | 54 if (length == 0) return []; |
| 55 Arrays.rangeCheck(this, start, length); | 55 Arrays.rangeCheck(this, start, length); |
| 56 List list = new _GrowableObjectArray<E>.withCapacity(length); | 56 List list = new _GrowableObjectArray<E>.withCapacity(length); |
| 57 list.length = length; | 57 list.length = length; |
| 58 Arrays.copy(this, start, list, 0, length); | 58 Arrays.copy(this, start, list, 0, length); |
| 59 return list; | 59 return list; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Collection interface. | 62 /** |
| 63 | 63 * Collection interface. |
| 64 bool contains(E element) => Collections.contains(this, element); | 64 */ |
| 65 | 65 |
| 66 void forEach(f(E element)) { | 66 void forEach(f(E element)) { |
| 67 Collections.forEach(this, f); | 67 Collections.forEach(this, f); |
| 68 } | 68 } |
| 69 | 69 |
| 70 Collection map(f(E element)) { | 70 Collection map(f(E element)) { |
| 71 return Collections.map( | 71 return Collections.map( |
| 72 this, new _GrowableObjectArray.withCapacity(length), f); | 72 this, new _GrowableObjectArray.withCapacity(length), f); |
| 73 } | 73 } |
| 74 | 74 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 List<E> getRange(int start, int length) { | 195 List<E> getRange(int start, int length) { |
| 196 if (length == 0) return []; | 196 if (length == 0) return []; |
| 197 Arrays.rangeCheck(this, start, length); | 197 Arrays.rangeCheck(this, start, length); |
| 198 List list = new List<E>(); | 198 List list = new List<E>(); |
| 199 list.length = length; | 199 list.length = length; |
| 200 Arrays.copy(this, start, list, 0, length); | 200 Arrays.copy(this, start, list, 0, length); |
| 201 return list; | 201 return list; |
| 202 } | 202 } |
| 203 | 203 |
| 204 // Collection interface. | 204 /** |
| 205 | 205 * Collection interface. |
| 206 bool contains(E element) => Collections.contains(this, element); | 206 */ |
| 207 | 207 |
| 208 void forEach(f(E element)) { | 208 void forEach(f(E element)) { |
| 209 Collections.forEach(this, f); | 209 Collections.forEach(this, f); |
| 210 } | 210 } |
| 211 | 211 |
| 212 Collection map(f(E element)) { | 212 Collection map(f(E element)) { |
| 213 return Collections.map( | 213 return Collections.map( |
| 214 this, new _GrowableObjectArray.withCapacity(length), f); | 214 this, new _GrowableObjectArray.withCapacity(length), f); |
| 215 } | 215 } |
| 216 | 216 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (!hasNext()) { | 306 if (!hasNext()) { |
| 307 throw const NoMoreElementsException(); | 307 throw const NoMoreElementsException(); |
| 308 } | 308 } |
| 309 return _array[_pos++]; | 309 return _array[_pos++]; |
| 310 } | 310 } |
| 311 | 311 |
| 312 final List<E> _array; | 312 final List<E> _array; |
| 313 final int _length; // Cache array length for faster access. | 313 final int _length; // Cache array length for faster access. |
| 314 int _pos; | 314 int _pos; |
| 315 } | 315 } |
| OLD | NEW |