Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: runtime/lib/growable_array.dart

Issue 12817003: Change getRange to sublist. Make getRange deprecated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 Arrays.copy(this, 101 Arrays.copy(this,
102 start, 102 start,
103 this, 103 this,
104 start + length, 104 start + length,
105 old_length - start); 105 old_length - start);
106 for (int i = start; i < start + length; i++) { 106 for (int i = start; i < start + length; i++) {
107 this[i] = initialValue; 107 this[i] = initialValue;
108 } 108 }
109 } 109 }
110 110
111 List<T> getRange(int start, int length) { 111 List<T> sublist(int start, [int end]) {
112 if (length == 0) return []; 112 Arrays.indicesCheck(this, start, end);
113 Arrays.rangeCheck(this, start, length); 113 if (end == null) end = length;
114 int length = end - start;
115 if (start == end) return <T>[];
114 List list = new _GrowableObjectArray<T>.withCapacity(length); 116 List list = new _GrowableObjectArray<T>.withCapacity(length);
115 list.length = length; 117 list.length = length;
116 Arrays.copy(this, start, list, 0, length); 118 Arrays.copy(this, start, list, 0, length);
117 return list; 119 return list;
118 } 120 }
119 121
122 List<T> getRange(int start, int length) => sublist(start, start + length);
123
120 factory _GrowableObjectArray(int length) { 124 factory _GrowableObjectArray(int length) {
121 var data = new _ObjectArray((length == 0) ? 4 : length); 125 var data = new _ObjectArray((length == 0) ? 4 : length);
122 var result = new _GrowableObjectArray<T>.withData(data); 126 var result = new _GrowableObjectArray<T>.withData(data);
123 result._setLength(length); 127 result._setLength(length);
124 return result; 128 return result;
125 } 129 }
126 130
127 factory _GrowableObjectArray.withCapacity(int capacity) { 131 factory _GrowableObjectArray.withCapacity(int capacity) {
128 var data = new _ObjectArray((capacity == 0)? 4 : capacity); 132 var data = new _ObjectArray((capacity == 0)? 4 : capacity);
129 return new _GrowableObjectArray<T>.withData(data); 133 return new _GrowableObjectArray<T>.withData(data);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 347 }
344 348
345 Set<T> toSet() { 349 Set<T> toSet() {
346 return new Set<T>.from(this); 350 return new Set<T>.from(this);
347 } 351 }
348 352
349 Map<int, T> asMap() { 353 Map<int, T> asMap() {
350 return IterableMixinWorkaround.asMapList(this); 354 return IterableMixinWorkaround.asMapList(this);
351 } 355 }
352 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698