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

Side by Side Diff: sdk/lib/internal/iterable.dart

Issue 1024843002: Change ListIterator to only check for concurrent modification at each iteration (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changelog. Created 5 years, 8 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
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_array.dart ('k') | tests/corelib/iterable_fold_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 313
314 /** 314 /**
315 * An [Iterator] that iterates a list-like [Iterable]. 315 * An [Iterator] that iterates a list-like [Iterable].
316 * 316 *
317 * All iterations is done in terms of [Iterable.length] and 317 * All iterations is done in terms of [Iterable.length] and
318 * [Iterable.elementAt]. These operations are fast for list-like 318 * [Iterable.elementAt]. These operations are fast for list-like
319 * iterables. 319 * iterables.
320 */ 320 */
321 class ListIterator<E> implements Iterator<E> { 321 class ListIterator<E> implements Iterator<E> {
322 final Iterable<E> _iterable; 322 final Iterable<E> _iterable;
323 final int _length; 323 final int _originalLength;
324 int _index; 324 int _index;
325 E _current; 325 E _current;
326 326
327 ListIterator(Iterable<E> iterable) 327 ListIterator(Iterable<E> iterable)
328 : _iterable = iterable, _length = iterable.length, _index = 0; 328 : _iterable = iterable, _originalLength = iterable.length, _index = 0;
329 329
330 E get current => _current; 330 E get current => _current;
331 331
332 bool moveNext() { 332 bool moveNext() {
333 int length = _iterable.length; 333 // Check for concurrent modifiction at each step in checked mode.
334 if (_length != length) { 334 assert((_originalLength == _iterable.length) ||
335 (throw new ConcurrentModificationError(_iterable)));
336 if (_index < _iterable.length) {
337 _current = _iterable.elementAt(_index);
338 _index++;
339 return true;
340 }
341 // Check for concurrent modification only at the end in production mode.
342 if (_originalLength != _iterable.length) {
335 throw new ConcurrentModificationError(_iterable); 343 throw new ConcurrentModificationError(_iterable);
336 } 344 }
337 if (_index >= length) { 345 _current = null;
338 _current = null; 346 return false;
339 return false;
340 }
341 _current = _iterable.elementAt(_index);
342 _index++;
343 return true;
344 } 347 }
345 } 348 }
346 349
347 typedef T _Transformation<S, T>(S value); 350 typedef T _Transformation<S, T>(S value);
348 351
349 class MappedIterable<S, T> extends Iterable<T> { 352 class MappedIterable<S, T> extends Iterable<T> {
350 final Iterable<S> _iterable; 353 final Iterable<S> _iterable;
351 final _Transformation<S, T> _f; 354 final _Transformation<S, T> _f;
352 355
353 factory MappedIterable(Iterable iterable, T function(S value)) { 356 factory MappedIterable(Iterable iterable, T function(S value)) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 * Creates errors throw by [Iterable] when the element count is wrong. 765 * Creates errors throw by [Iterable] when the element count is wrong.
763 */ 766 */
764 abstract class IterableElementError { 767 abstract class IterableElementError {
765 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ 768 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */
766 static StateError noElement() => new StateError("No element"); 769 static StateError noElement() => new StateError("No element");
767 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ 770 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */
768 static StateError tooMany() => new StateError("Too many elements"); 771 static StateError tooMany() => new StateError("Too many elements");
769 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ 772 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */
770 static StateError tooFew() => new StateError("Too few elements"); 773 static StateError tooFew() => new StateError("Too few elements");
771 } 774 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_array.dart ('k') | tests/corelib/iterable_fold_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698