about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-05-02 04:46:58 -0700
committerbors <bors@rust-lang.org>2016-05-02 04:46:58 -0700
commite1a575cb077d2070cc4527fa43bf9ef790f89f04 (patch)
treeeabbda78efcc84bac11c9d5a6bf85147b37b3287 /src/libcoretest
parentd3c2c71988c1b2707c6c2ba19f14dc1ffe6a56fc (diff)
parente6201cfb5cabc636a1dbfb1e543e5485639497a4 (diff)
downloadrust-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/libcoretest')
-rw-r--r--src/libcoretest/iter.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index 6c0cb03b5f7..56b10d0b79b 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -134,6 +134,19 @@ fn test_iterator_chain_count() {
 }
 
 #[test]
+fn test_iterator_chain_find() {
+    let xs = [0, 1, 2, 3, 4, 5];
+    let ys = [30, 40, 50, 60];
+    let mut iter = xs.iter().chain(&ys);
+    assert_eq!(iter.find(|&&i| i == 4), Some(&4));
+    assert_eq!(iter.next(), Some(&5));
+    assert_eq!(iter.find(|&&i| i == 40), Some(&40));
+    assert_eq!(iter.next(), Some(&50));
+    assert_eq!(iter.find(|&&i| i == 100), None);
+    assert_eq!(iter.next(), None);
+}
+
+#[test]
 fn test_filter_map() {
     let it = (0..).step_by(1).take(10)
         .filter_map(|x| if x % 2 == 0 { Some(x*x) } else { None });