| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 void removeRange(int start, int end) { | 72 void removeRange(int start, int end) { |
| 73 Arrays.indicesCheck(this, start, end); | 73 Arrays.indicesCheck(this, start, end); |
| 74 Arrays.copy(this, | 74 Arrays.copy(this, |
| 75 end, | 75 end, |
| 76 this, | 76 this, |
| 77 start, | 77 start, |
| 78 this.length - end); | 78 this.length - end); |
| 79 this.length = this.length - (end - start); | 79 this.length = this.length - (end - start); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void insertRange(int start, int length, [T initialValue = null]) { | |
| 83 if (length == 0) { | |
| 84 return; | |
| 85 } | |
| 86 if ((length < 0) || (length is! int)) { | |
| 87 throw new ArgumentError("invalid length specified $length"); | |
| 88 } | |
| 89 if (start < 0 || start > this.length) { | |
| 90 throw new RangeError.value(start); | |
| 91 } | |
| 92 var old_length = this.length; | |
| 93 this.length = old_length + length; // Will expand if needed. | |
| 94 Arrays.copy(this, | |
| 95 start, | |
| 96 this, | |
| 97 start + length, | |
| 98 old_length - start); | |
| 99 for (int i = start; i < start + length; i++) { | |
| 100 this[i] = initialValue; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 List<T> sublist(int start, [int end]) { | 82 List<T> sublist(int start, [int end]) { |
| 105 Arrays.indicesCheck(this, start, end); | 83 Arrays.indicesCheck(this, start, end); |
| 106 if (end == null) end = length; | 84 if (end == null) end = length; |
| 107 int length = end - start; | 85 int length = end - start; |
| 108 if (start == end) return <T>[]; | 86 if (start == end) return <T>[]; |
| 109 List list = new _GrowableObjectArray<T>.withCapacity(length); | 87 List list = new _GrowableObjectArray<T>.withCapacity(length); |
| 110 list.length = length; | 88 list.length = length; |
| 111 Arrays.copy(this, start, list, 0, length); | 89 Arrays.copy(this, start, list, 0, length); |
| 112 return list; | 90 return list; |
| 113 } | 91 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 312 } |
| 335 | 313 |
| 336 Set<T> toSet() { | 314 Set<T> toSet() { |
| 337 return new Set<T>.from(this); | 315 return new Set<T>.from(this); |
| 338 } | 316 } |
| 339 | 317 |
| 340 Map<int, T> asMap() { | 318 Map<int, T> asMap() { |
| 341 return IterableMixinWorkaround.asMapList(this); | 319 return IterableMixinWorkaround.asMapList(this); |
| 342 } | 320 } |
| 343 } | 321 } |
| OLD | NEW |