OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of dart._internal; | 5 part of dart._internal; |
6 | 6 |
7 /** | 7 /** |
8 * Marker interface for [Iterable] subclasses that have an efficient | 8 * Marker interface for [Iterable] subclasses that have an efficient |
9 * [length] implementation. | 9 * [length] implementation. |
10 */ | 10 */ |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 if (count < 0) throw new RangeError.value(count); | 287 if (count < 0) throw new RangeError.value(count); |
288 if (_endOrLength == null) { | 288 if (_endOrLength == null) { |
289 return new SubListIterable<E>(_iterable, _start, _start + count); | 289 return new SubListIterable<E>(_iterable, _start, _start + count); |
290 } else { | 290 } else { |
291 int newEnd = _start + count; | 291 int newEnd = _start + count; |
292 if (_endOrLength < newEnd) return this; | 292 if (_endOrLength < newEnd) return this; |
293 return new SubListIterable<E>(_iterable, _start, newEnd); | 293 return new SubListIterable<E>(_iterable, _start, newEnd); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 List<E> toList({bool growable: false}) { | 297 List<E> toList({bool growable: true}) { |
298 int start = _start; | 298 int start = _start; |
299 int end = _iterable.length; | 299 int end = _iterable.length; |
300 if (_endOrLength != null && _endOrLength < end) end = _endOrLength; | 300 if (_endOrLength != null && _endOrLength < end) end = _endOrLength; |
301 int length = end - start; | 301 int length = end - start; |
302 if (length < 0) length = 0; | 302 if (length < 0) length = 0; |
303 List result = growable ? (new List<E>()..length = length) | 303 List result = growable ? (new List<E>()..length = length) |
304 : new List<E>(length); | 304 : new List<E>(length); |
305 for (int i = 0; i < length; i++) { | 305 for (int i = 0; i < length; i++) { |
306 result[i] = _iterable.elementAt(start + i); | 306 result[i] = _iterable.elementAt(start + i); |
307 if (_iterable.length < end) throw new ConcurrentModificationError(this); | 307 if (_iterable.length < end) throw new ConcurrentModificationError(this); |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 * Creates errors throw by [Iterable] when the element count is wrong. | 1165 * Creates errors throw by [Iterable] when the element count is wrong. |
1166 */ | 1166 */ |
1167 abstract class IterableElementError { | 1167 abstract class IterableElementError { |
1168 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ | 1168 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ |
1169 static StateError noElement() => new StateError("No element"); | 1169 static StateError noElement() => new StateError("No element"); |
1170 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ | 1170 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ |
1171 static StateError tooMany() => new StateError("Too many elements"); | 1171 static StateError tooMany() => new StateError("Too many elements"); |
1172 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ | 1172 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ |
1173 static StateError tooFew() => new StateError("Too few elements"); | 1173 static StateError tooFew() => new StateError("Too few elements"); |
1174 } | 1174 } |
OLD | NEW |