Chromium Code Reviews| 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 WhereIterable(this._iterable, this._f); | 422 WhereIterable(this._iterable, this._f); |
| 423 | 423 |
| 424 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); | 424 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); |
| 425 | 425 |
| 426 // Specialization of [Iterable.map] to non-EfficientLengthIterable. | 426 // Specialization of [Iterable.map] to non-EfficientLengthIterable. |
| 427 Iterable<T> map<T>(T f(E element)) => new MappedIterable<E, T>._(this, f); | 427 Iterable<T> map<T>(T f(E element)) => new MappedIterable<E, T>._(this, f); |
| 428 } | 428 } |
| 429 | 429 |
| 430 class WhereIterator<E> extends Iterator<E> { | 430 class WhereIterator<E> extends Iterator<E> { |
| 431 final Iterator<E> _iterator; | 431 final Iterator<E> _iterator; |
| 432 final _ElementPredicate _f; | 432 final _ElementPredicate<E> _f; |
| 433 | 433 |
| 434 WhereIterator(this._iterator, this._f); | 434 WhereIterator(this._iterator, this._f); |
| 435 | 435 |
| 436 bool moveNext() { | 436 bool moveNext() { |
| 437 while (_iterator.moveNext()) { | 437 while (_iterator.moveNext()) { |
| 438 if (_f(_iterator.current)) { | 438 if (_f(_iterator.current)) { |
|
vsm
2017/04/27 13:29:28
The change above removes the dynamic check on _f h
| |
| 439 return true; | 439 return true; |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 return false; | 442 return false; |
| 443 } | 443 } |
| 444 | 444 |
| 445 E get current => _iterator.current; | 445 E get current => _iterator.current; |
| 446 } | 446 } |
| 447 | 447 |
| 448 typedef Iterable<T> _ExpandFunction<S, T>(S sourceElement); | 448 typedef Iterable<T> _ExpandFunction<S, T>(S sourceElement); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 * Creates errors throw by [Iterable] when the element count is wrong. | 762 * Creates errors throw by [Iterable] when the element count is wrong. |
| 763 */ | 763 */ |
| 764 abstract class IterableElementError { | 764 abstract class IterableElementError { |
| 765 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ | 765 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ |
| 766 static StateError noElement() => new StateError("No element"); | 766 static StateError noElement() => new StateError("No element"); |
| 767 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ | 767 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ |
| 768 static StateError tooMany() => new StateError("Too many elements"); | 768 static StateError tooMany() => new StateError("Too many elements"); |
| 769 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ | 769 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ |
| 770 static StateError tooFew() => new StateError("Too few elements"); | 770 static StateError tooFew() => new StateError("Too few elements"); |
| 771 } | 771 } |
| OLD | NEW |