Chromium Code Reviews| 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(length) native "ObjectArray_allocate"; | 9 factory _ObjectArray(length) native "ObjectArray_allocate"; |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 void removeRange(int start, int length) { | 75 void removeRange(int start, int length) { |
| 76 throw new UnsupportedError( | 76 throw new UnsupportedError( |
| 77 "Cannot remove range of a non-extendable array"); | 77 "Cannot remove range of a non-extendable array"); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void insertRange(int start, int length, [E initialValue = null]) { | 80 void insertRange(int start, int length, [E initialValue = null]) { |
| 81 throw new UnsupportedError( | 81 throw new UnsupportedError( |
| 82 "Cannot insert range in a non-extendable array"); | 82 "Cannot insert range in a non-extendable array"); |
| 83 } | 83 } |
| 84 | 84 |
| 85 List<E> getRange(int start, int length) { | 85 |
| 86 if (length == 0) return []; | 86 List<E> sublist(int start, [int end]) { |
| 87 Arrays.rangeCheck(this, start, length); | 87 Arrays.indicesCheck(this, start, end); |
|
srdjan
2013/03/18 16:24:41
It seems that this version of sublist is considera
| |
| 88 if (end == null) end = this.length; | |
| 89 int length = end - start; | |
| 90 if (start == end) return []; | |
| 88 List list = new _GrowableObjectArray<E>.withCapacity(length); | 91 List list = new _GrowableObjectArray<E>.withCapacity(length); |
| 89 list.length = length; | 92 list.length = length; |
| 90 Arrays.copy(this, start, list, 0, length); | 93 Arrays.copy(this, start, list, 0, length); |
| 91 return list; | 94 return list; |
| 92 } | 95 } |
| 93 | 96 |
| 97 List<E> getRange(int start, int length) => sublist(start, start + length); | |
| 98 | |
| 94 // Iterable interface. | 99 // Iterable interface. |
| 95 | 100 |
| 96 bool contains(E element) { | 101 bool contains(E element) { |
| 97 return IterableMixinWorkaround.contains(this, element); | 102 return IterableMixinWorkaround.contains(this, element); |
| 98 } | 103 } |
| 99 | 104 |
| 100 void forEach(f(E element)) { | 105 void forEach(f(E element)) { |
| 101 IterableMixinWorkaround.forEach(this, f); | 106 IterableMixinWorkaround.forEach(this, f); |
| 102 } | 107 } |
| 103 | 108 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 void removeRange(int start, int length) { | 323 void removeRange(int start, int length) { |
| 319 throw new UnsupportedError( | 324 throw new UnsupportedError( |
| 320 "Cannot remove range of an immutable array"); | 325 "Cannot remove range of an immutable array"); |
| 321 } | 326 } |
| 322 | 327 |
| 323 void insertRange(int start, int length, [E initialValue = null]) { | 328 void insertRange(int start, int length, [E initialValue = null]) { |
| 324 throw new UnsupportedError( | 329 throw new UnsupportedError( |
| 325 "Cannot insert range in an immutable array"); | 330 "Cannot insert range in an immutable array"); |
| 326 } | 331 } |
| 327 | 332 |
| 328 List<E> getRange(int start, int length) { | 333 List<E> sublist(int start, [int end]) { |
| 329 if (length == 0) return []; | 334 Arrays.indicesCheck(this, start, end); |
| 330 Arrays.rangeCheck(this, start, length); | 335 if (end == null) end = this.length; |
| 336 int length = end - start; | |
| 337 if (start == end) return []; | |
| 331 List list = new List<E>(); | 338 List list = new List<E>(); |
| 332 list.length = length; | 339 list.length = length; |
| 333 Arrays.copy(this, start, list, 0, length); | 340 Arrays.copy(this, start, list, 0, length); |
| 334 return list; | 341 return list; |
| 335 } | 342 } |
| 336 | 343 |
| 344 List<E> getRange(int start, int length) => sublist(start, start + length); | |
| 345 | |
| 337 // Collection interface. | 346 // Collection interface. |
| 338 | 347 |
| 339 bool contains(E element) { | 348 bool contains(E element) { |
| 340 return IterableMixinWorkaround.contains(this, element); | 349 return IterableMixinWorkaround.contains(this, element); |
| 341 } | 350 } |
| 342 | 351 |
| 343 void forEach(f(E element)) { | 352 void forEach(f(E element)) { |
| 344 IterableMixinWorkaround.forEach(this, f); | 353 IterableMixinWorkaround.forEach(this, f); |
| 345 } | 354 } |
| 346 | 355 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 } | 525 } |
| 517 _position = _length; | 526 _position = _length; |
| 518 _current = null; | 527 _current = null; |
| 519 return false; | 528 return false; |
| 520 } | 529 } |
| 521 | 530 |
| 522 E get current { | 531 E get current { |
| 523 return _current; | 532 return _current; |
| 524 } | 533 } |
| 525 } | 534 } |
| OLD | NEW |