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

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

Issue 1318943005: Update range errors to agree on the numbers. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: More tests Created 5 years, 3 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
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 _GrowableList<T> extends ListBase<T> { 5 class _GrowableList<T> extends ListBase<T> {
6 6
7 void insert(int index, T element) { 7 void insert(int index, T element) {
8 if ((index < 0) || (index > length)) { 8 if ((index < 0) || (index > length)) {
9 throw new RangeError.range(index, 0, length); 9 throw new RangeError.range(index, 0, length);
10 } 10 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (iterable is List) { 63 if (iterable is List) {
64 setRange(index, index + iterable.length, iterable); 64 setRange(index, index + iterable.length, iterable);
65 } else { 65 } else {
66 for (T element in iterable) { 66 for (T element in iterable) {
67 this[index++] = element; 67 this[index++] = element;
68 } 68 }
69 } 69 }
70 } 70 }
71 71
72 void removeRange(int start, int end) { 72 void removeRange(int start, int end) {
73 Lists.indicesCheck(this, start, end); 73 RangeError.checkValidRange(start, end, this.length);
74 Lists.copy(this, end, this, start, this.length - end); 74 Lists.copy(this, end, this, start, this.length - end);
75 this.length = this.length - (end - start); 75 this.length = this.length - (end - start);
76 } 76 }
77 77
78 List<T> sublist(int start, [int end]) { 78 List<T> sublist(int start, [int end]) {
79 Lists.indicesCheck(this, start, end); 79 end = RangeError.checkValidRange(start, end, this.length);
80 if (end == null) end = this.length;
81 int length = end - start; 80 int length = end - start;
82 if (length == 0) return <T>[]; 81 if (length == 0) return <T>[];
83 List list = new _List(length); 82 List list = new _List(length);
84 for (int i = 0; i < length; i++) { 83 for (int i = 0; i < length; i++) {
85 list[i] = this[start + i]; 84 list[i] = this[start + i];
86 } 85 }
87 var result = new _GrowableList<T>.withData(list); 86 var result = new _GrowableList<T>.withData(list);
88 result._setLength(length); 87 result._setLength(length);
89 return result; 88 return result;
90 } 89 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 result._setLength(length); 335 result._setLength(length);
337 return result; 336 return result;
338 } 337 }
339 return growable ? <T>[] : new List<T>(0); 338 return growable ? <T>[] : new List<T>(0);
340 } 339 }
341 340
342 Set<T> toSet() { 341 Set<T> toSet() {
343 return new Set<T>.from(this); 342 return new Set<T>.from(this);
344 } 343 }
345 } 344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698