-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
Iterators.peekingIterator()
reuse AbstractIterator.peek()
.
Currently, `Iterators.peekingIterator()` will treat `AbstractIterator` just like any other iterator, and will call `next()` to get the element, which it then stashes. This is wasteful, since `AbstractIterator` already provides a `peek()` method that is designed to be compatible with the `PeekingIterator` interface, so use it instead. `AbstractIterator` subclasses `UnmodifiableIterator`, so we can do likewise with the `PeekingIterator` forwarder. The resulting forwarder is much more lightweight than the default `Iterators.peekingIterator()` implementation.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters