From ac6ea8f1f6cd90502faee181dd054565802de4af Mon Sep 17 00:00:00 2001 From: Stefan Kreutz Date: Tue, 7 Feb 2023 18:01:47 +0100 Subject: Remove useless conversion from Range into Iterator --- src/lib.rs | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2d34b1c..3114426 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ //! use parseq::ParallelIterator; //! //! let mut iter = (0..3) -//! .into_iter() //! .map_parallel(|i| { //! // Insert heavy computation here ... //! std::thread::sleep(Duration::from_millis((i % 3) * 10)); @@ -73,7 +72,6 @@ pub trait ParallelIterator { /// use parseq::ParallelIterator; /// /// let mut iter = (0..3) - /// .into_iter() /// .map_parallel(|i| { /// std::thread::sleep(Duration::from_millis((i % 3) * 10)); /// i @@ -121,7 +119,6 @@ pub trait ParallelIterator { /// use parseq::ParallelIterator; /// /// let mut iter = (0..3) - /// .into_iter() /// .map_parallel_limit(2, 16, |i| { /// std::thread::sleep(Duration::from_millis((i % 3) * 10)); /// i @@ -365,45 +362,41 @@ mod tests { #[test] fn map_with_multiple_threads() { assert!((0..100) - .into_iter() .map_parallel_limit(5, 7, |i| { std::thread::sleep(Duration::from_millis((i % 3) * 10)); 2 * i }) - .eq((0..100).into_iter().map(|i| 2 * i))); + .eq((0..100).map(|i| 2 * i))); } #[test] fn map_with_single_thread() { assert!((0..100) - .into_iter() .map_parallel_limit(1, 7, |i| { std::thread::sleep(Duration::from_millis((i % 3) * 10)); 2 * i }) - .eq((0..100).into_iter().map(|i| 2 * i))); + .eq((0..100).map(|i| 2 * i))); } #[test] fn map_with_zero_threads() { assert!((0..100) - .into_iter() .map_parallel_limit(0, 7, |i| { std::thread::sleep(Duration::from_millis((i % 3) * 10)); 2 * i }) - .eq((0..100).into_iter().map(|i| 2 * i))); + .eq((0..100).map(|i| 2 * i))); } #[test] fn map_with_zero_buffer_size() { assert!((0..100) - .into_iter() .map_parallel_limit(5, 0, |i| { std::thread::sleep(Duration::from_millis((i % 3) * 10)); 2 * i }) - .eq((0..100).into_iter().map(|i| 2 * i))); + .eq((0..100).map(|i| 2 * i))); } #[test] @@ -428,9 +421,7 @@ mod tests { #[test] fn map_is_lazy() { - let _iter = (0..10) - .into_iter() - .map_parallel_limit(5, 7, |_| panic!("eager evaluation")); + let _iter = (0..10).map_parallel_limit(5, 7, |_| panic!("eager evaluation")); } #[test] @@ -438,7 +429,6 @@ mod tests { #[ntest::timeout(1000)] fn map_propagates_panic() { let _ = (0..100) - .into_iter() .map_parallel_limit(5, 7, |i| { if i == 13 { panic!("boom"); @@ -480,7 +470,7 @@ mod tests { map.in_i = usize::MAX - 13; map.out_i = usize::MAX - 13; - assert!(map.eq((0..100).into_iter().map(|i| 2 * i))); + assert!(map.eq((0..100).map(|i| 2 * i))); } #[test] @@ -510,16 +500,14 @@ mod tests { let counter = Arc::new(Mutex::new(0)); let count = counter.clone(); - let mut iter = (0..) - .into_iter() - .map_parallel_limit(threads, buffer_size, move |i| { - if i < consume { - std::thread::sleep(Duration::from_millis(100)); - } - let mut counter = counter.lock().unwrap(); - *counter += 1; - 2 * i - }); + let mut iter = (0..).map_parallel_limit(threads, buffer_size, move |i| { + if i < consume { + std::thread::sleep(Duration::from_millis(100)); + } + let mut counter = counter.lock().unwrap(); + *counter += 1; + 2 * i + }); for _ in 0..consume { iter.next(); } -- cgit v1.2.3