diff options
| author | bors <bors@rust-lang.org> | 2016-05-02 04:46:58 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-02 04:46:58 -0700 |
| commit | e1a575cb077d2070cc4527fa43bf9ef790f89f04 (patch) | |
| tree | eabbda78efcc84bac11c9d5a6bf85147b37b3287 /src/libcore | |
| parent | d3c2c71988c1b2707c6c2ba19f14dc1ffe6a56fc (diff) | |
| parent | e6201cfb5cabc636a1dbfb1e543e5485639497a4 (diff) | |
| download | rust-e1a575cb077d2070cc4527fa43bf9ef790f89f04.tar.gz rust-e1a575cb077d2070cc4527fa43bf9ef790f89f04.zip | |
Auto merge of #33289 - birkenfeld:chain-find, r=bluss
Implement find() on Chain iterators This results in a roughly 2x speedup compared to the default impl "inherited" from Iterator. Benchmark: https://gist.github.com/birkenfeld/aa9b92cb7d55666dd4821207527eaf5b
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/iter/mod.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index abc199cd182..17f7c0a773e 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -542,6 +542,23 @@ impl<A, B> Iterator for Chain<A, B> where } #[inline] + fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where + P: FnMut(&Self::Item) -> bool, + { + match self.state { + ChainState::Both => match self.a.find(&mut predicate) { + None => { + self.state = ChainState::Back; + self.b.find(predicate) + } + v => v + }, + ChainState::Front => self.a.find(predicate), + ChainState::Back => self.b.find(predicate), + } + } + + #[inline] fn last(self) -> Option<A::Item> { match self.state { ChainState::Both => { |
