| 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 factory _GrowableObjectArray._uninstantiable() { | 6 factory _GrowableObjectArray._uninstantiable() { |
| 7 throw new UnsupportedError( | 7 throw new UnsupportedError( |
| 8 "GrowableObjectArray can only be allocated by the VM"); | 8 "GrowableObjectArray can only be allocated by the VM"); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 Iterable<T> getRange(int start, int end) { | 64 Iterable<T> getRange(int start, int end) { |
| 65 return IterableMixinWorkaround.getRangeList(this, start, end); | 65 return IterableMixinWorkaround.getRangeList(this, start, end); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) { | 68 void setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) { |
| 69 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | 69 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void removeRange(int start, int length) { | 72 void removeRange(int start, int end) { |
| 73 if (length == 0) { | 73 Arrays.indicesCheck(this, start, end); |
| 74 return; | |
| 75 } | |
| 76 Arrays.rangeCheck(this, start, length); | |
| 77 Arrays.copy(this, | 74 Arrays.copy(this, |
| 78 start + length, | 75 end, |
| 79 this, | 76 this, |
| 80 start, | 77 start, |
| 81 this.length - length - start); | 78 this.length - end); |
| 82 this.length = this.length - length; | 79 this.length = this.length - (end - start); |
| 83 } | |
| 84 | |
| 85 void insertRange(int start, int length, [T initialValue = null]) { | |
| 86 if (length == 0) { | |
| 87 return; | |
| 88 } | |
| 89 if ((length < 0) || (length is! int)) { | |
| 90 throw new ArgumentError("invalid length specified $length"); | |
| 91 } | |
| 92 if (start < 0 || start > this.length) { | |
| 93 throw new RangeError.value(start); | |
| 94 } | |
| 95 var old_length = this.length; | |
| 96 this.length = old_length + length; // Will expand if needed. | |
| 97 Arrays.copy(this, | |
| 98 start, | |
| 99 this, | |
| 100 start + length, | |
| 101 old_length - start); | |
| 102 for (int i = start; i < start + length; i++) { | |
| 103 this[i] = initialValue; | |
| 104 } | |
| 105 } | 80 } |
| 106 | 81 |
| 107 List<T> sublist(int start, [int end]) { | 82 List<T> sublist(int start, [int end]) { |
| 108 Arrays.indicesCheck(this, start, end); | 83 Arrays.indicesCheck(this, start, end); |
| 109 if (end == null) end = length; | 84 if (end == null) end = length; |
| 110 int length = end - start; | 85 int length = end - start; |
| 111 if (start == end) return <T>[]; | 86 if (start == end) return <T>[]; |
| 112 List list = new _GrowableObjectArray<T>.withCapacity(length); | 87 List list = new _GrowableObjectArray<T>.withCapacity(length); |
| 113 list.length = length; | 88 list.length = length; |
| 114 Arrays.copy(this, start, list, 0, length); | 89 Arrays.copy(this, start, list, 0, length); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 312 } |
| 338 | 313 |
| 339 Set<T> toSet() { | 314 Set<T> toSet() { |
| 340 return new Set<T>.from(this); | 315 return new Set<T>.from(this); |
| 341 } | 316 } |
| 342 | 317 |
| 343 Map<int, T> asMap() { | 318 Map<int, T> asMap() { |
| 344 return IterableMixinWorkaround.asMapList(this); | 319 return IterableMixinWorkaround.asMapList(this); |
| 345 } | 320 } |
| 346 } | 321 } |
| OLD | NEW |