| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void retainWhere(bool test(E element)) { | 47 void retainWhere(bool test(E element)) { |
| 48 throw new UnsupportedError( | 48 throw new UnsupportedError( |
| 49 "Cannot remove element of a non-extendable array"); | 49 "Cannot remove element of a non-extendable array"); |
| 50 } | 50 } |
| 51 | 51 |
| 52 Iterable<E> getRange(int start, [int end]) { | 52 Iterable<E> getRange(int start, [int end]) { |
| 53 return IterableMixinWorkaround.getRangeList(this, start, end); | 53 return IterableMixinWorkaround.getRangeList(this, start, end); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // List interface. | 56 // List interface. |
| 57 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { | 57 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 58 if (length < 0) { | 58 if (start < 0 || start > this.length) { |
| 59 throw new ArgumentError("negative length $length"); | 59 throw new RangeError.range(start, 0, this.length); |
| 60 } | 60 } |
| 61 if (from is _ObjectArray) { | 61 if (end < 0 || end > this.length) { |
| 62 _copyFromObjectArray(from, startFrom, start, length); | 62 throw new RangeError.range(end, start, this.length); |
| 63 } |
| 64 int length = end - start; |
| 65 if (length == 0) return; |
| 66 |
| 67 if (iterable is _ObjectArray) { |
| 68 _copyFromObjectArray(iterable, skipCount, start, length); |
| 63 } else { | 69 } else { |
| 64 Arrays.copy(from, startFrom, this, start, length); | 70 List otherList; |
| 71 int otherStart; |
| 72 if (iterable is List) { |
| 73 otherList = iterable; |
| 74 otherStart = skipCount; |
| 75 } else { |
| 76 otherList = |
| 77 iterable.skip(skipCount).take(length).toList(growable: false); |
| 78 otherStart = 0; |
| 79 } |
| 80 Arrays.copy(otherList, otherStart, this, start, length); |
| 65 } | 81 } |
| 66 } | 82 } |
| 67 | 83 |
| 68 void removeRange(int start, int length) { | 84 void removeRange(int start, int length) { |
| 69 throw new UnsupportedError( | 85 throw new UnsupportedError( |
| 70 "Cannot remove range of a non-extendable array"); | 86 "Cannot remove range of a non-extendable array"); |
| 71 } | 87 } |
| 72 | 88 |
| 73 void insertRange(int start, int length, [E initialValue = null]) { | 89 void insertRange(int start, int length, [E initialValue = null]) { |
| 74 throw new UnsupportedError( | 90 throw new UnsupportedError( |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 void retainWhere(bool test(E element)) { | 301 void retainWhere(bool test(E element)) { |
| 286 throw new UnsupportedError( | 302 throw new UnsupportedError( |
| 287 "Cannot modify an immutable array"); | 303 "Cannot modify an immutable array"); |
| 288 } | 304 } |
| 289 | 305 |
| 290 void copyFrom(List src, int srcStart, int dstStart, int count) { | 306 void copyFrom(List src, int srcStart, int dstStart, int count) { |
| 291 throw new UnsupportedError( | 307 throw new UnsupportedError( |
| 292 "Cannot modify an immutable array"); | 308 "Cannot modify an immutable array"); |
| 293 } | 309 } |
| 294 | 310 |
| 295 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { | 311 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 296 throw new UnsupportedError( | 312 throw new UnsupportedError( |
| 297 "Cannot modify an immutable array"); | 313 "Cannot modify an immutable array"); |
| 298 } | 314 } |
| 299 | 315 |
| 300 void removeRange(int start, int length) { | 316 void removeRange(int start, int length) { |
| 301 throw new UnsupportedError( | 317 throw new UnsupportedError( |
| 302 "Cannot remove range of an immutable array"); | 318 "Cannot remove range of an immutable array"); |
| 303 } | 319 } |
| 304 | 320 |
| 305 void insertRange(int start, int length, [E initialValue = null]) { | 321 void insertRange(int start, int length, [E initialValue = null]) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 516 } |
| 501 _position = _length; | 517 _position = _length; |
| 502 _current = null; | 518 _current = null; |
| 503 return false; | 519 return false; |
| 504 } | 520 } |
| 505 | 521 |
| 506 E get current { | 522 E get current { |
| 507 return _current; | 523 return _current; |
| 508 } | 524 } |
| 509 } | 525 } |
| OLD | NEW |