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 _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 Loading... |
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 Loading... |
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 } |
OLD | NEW |