Skip to content

Commit 844cd39

Browse files
committed
Change getRange to sublist. Make getRange deprecated.
This changes the exception behavior of getRange. It used to accept a length of zero, no matter what start value. Now the start value must be a valid list index. Review URL: https://codereview.chromium.org//12817003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20064 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 058fb19 commit 844cd39

File tree

61 files changed

+1065
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1065
-394
lines changed

pkg/analyzer_experimental/lib/src/generated/java_core.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ class ListWrapper<E> extends Collection<E> implements List<E> {
313313

314314
Iterable<E> get reversed => elements.reversed;
315315

316-
List<E> getRange(int start, int length) {
317-
return elements.getRange(start, length);
318-
}
316+
List<E> sublist(int start, [int end]) => elements.sublist(start, end);
317+
318+
List<E> getRange(int start, int length) => sublist(start, start + length);
319319

320320
void setRange(int start, int length, List<E> from, [int startFrom]) {
321321
elements.setRange(start, length, from, startFrom);

pkg/intl/lib/src/date_format_helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class _Stream {
9898
min(index + howMany, contents.length));
9999
} else {
100100
// Assume List
101-
result = contents.getRange(index, howMany);
101+
result = contents.sublist(index, index + howMany);
102102
}
103103
return result;
104104
}

pkg/intl/test/date_time_format_test_core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ List oddLocales() {
184184
* Return a set of a few locales to run just the tests on a small sample.
185185
*/
186186
List smallSetOfLocales() {
187-
return allLocales().getRange(0,10);
187+
return allLocales().sublist(0,10);
188188
}
189189

190190
/**

pkg/scheduled_test/lib/src/descriptor/directory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Directory extends descriptor.Entry {
6262
throw "Found multiple entries named '${split.first}' within "
6363
"$nameDescription.";
6464
} else {
65-
var remainingPath = split.getRange(1, split.length - 1);
65+
var remainingPath = split.sublist(1);
6666
if (remainingPath.isEmpty) {
6767
return matchingEntries.first.read();
6868
} else {

runtime/lib/array.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ class _ObjectArray<E> implements List<E> {
8282
"Cannot insert range in a non-extendable array");
8383
}
8484

85-
List<E> getRange(int start, int length) {
86-
if (length == 0) return [];
87-
Arrays.rangeCheck(this, start, length);
85+
86+
List<E> sublist(int start, [int end]) {
87+
Arrays.indicesCheck(this, start, end);
88+
if (end == null) end = this.length;
89+
int length = end - start;
90+
if (start == end) return [];
8891
List list = new _GrowableObjectArray<E>.withCapacity(length);
8992
list.length = length;
9093
Arrays.copy(this, start, list, 0, length);
9194
return list;
9295
}
9396

97+
List<E> getRange(int start, int length) => sublist(start, start + length);
98+
9499
// Iterable interface.
95100

96101
bool contains(E element) {
@@ -325,15 +330,19 @@ class _ImmutableArray<E> implements List<E> {
325330
"Cannot insert range in an immutable array");
326331
}
327332

328-
List<E> getRange(int start, int length) {
329-
if (length == 0) return [];
330-
Arrays.rangeCheck(this, start, length);
333+
List<E> sublist(int start, [int end]) {
334+
Arrays.indicesCheck(this, start, end);
335+
if (end == null) end = this.length;
336+
int length = end - start;
337+
if (start == end) return [];
331338
List list = new List<E>();
332339
list.length = length;
333340
Arrays.copy(this, start, list, 0, length);
334341
return list;
335342
}
336343

344+
List<E> getRange(int start, int length) => sublist(start, start + length);
345+
337346
// Collection interface.
338347

339348
bool contains(E element) {

0 commit comments

Comments
 (0)