| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 Arrays.copy(this, | 79 Arrays.copy(this, |
| 80 start, | 80 start, |
| 81 this, | 81 this, |
| 82 start + length, | 82 start + length, |
| 83 old_length - start); | 83 old_length - start); |
| 84 for (int i = start; i < start + length; i++) { | 84 for (int i = start; i < start + length; i++) { |
| 85 this[i] = initialValue; | 85 this[i] = initialValue; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 List<T> getRange(int start, int length) { | 89 List<T> sublist(int start, [int end]) { |
| 90 if (length == 0) return []; | 90 Arrays.indicesCheck(this, start, end); |
| 91 Arrays.rangeCheck(this, start, length); | 91 if (end == null) end = length; |
| 92 int length = end - start; |
| 93 if (start == end) return <T>[]; |
| 92 List list = new _GrowableObjectArray<T>.withCapacity(length); | 94 List list = new _GrowableObjectArray<T>.withCapacity(length); |
| 93 list.length = length; | 95 list.length = length; |
| 94 Arrays.copy(this, start, list, 0, length); | 96 Arrays.copy(this, start, list, 0, length); |
| 95 return list; | 97 return list; |
| 96 } | 98 } |
| 97 | 99 |
| 100 List<T> getRange(int start, int length) => sublist(start, start + length); |
| 101 |
| 98 factory _GrowableObjectArray(int length) { | 102 factory _GrowableObjectArray(int length) { |
| 99 var data = new _ObjectArray((length == 0) ? 4 : length); | 103 var data = new _ObjectArray((length == 0) ? 4 : length); |
| 100 var result = new _GrowableObjectArray<T>.withData(data); | 104 var result = new _GrowableObjectArray<T>.withData(data); |
| 101 result._setLength(length); | 105 result._setLength(length); |
| 102 return result; | 106 return result; |
| 103 } | 107 } |
| 104 | 108 |
| 105 factory _GrowableObjectArray.withCapacity(int capacity) { | 109 factory _GrowableObjectArray.withCapacity(int capacity) { |
| 106 var data = new _ObjectArray((capacity == 0)? 4 : capacity); | 110 var data = new _ObjectArray((capacity == 0)? 4 : capacity); |
| 107 return new _GrowableObjectArray<T>.withData(data); | 111 return new _GrowableObjectArray<T>.withData(data); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 325 } |
| 322 | 326 |
| 323 Set<T> toSet() { | 327 Set<T> toSet() { |
| 324 return new Set<T>.from(this); | 328 return new Set<T>.from(this); |
| 325 } | 329 } |
| 326 | 330 |
| 327 Map<int, T> asMap() { | 331 Map<int, T> asMap() { |
| 328 return IterableMixinWorkaround.asMapList(this); | 332 return IterableMixinWorkaround.asMapList(this); |
| 329 } | 333 } |
| 330 } | 334 } |
| OLD | NEW |