diff --git a/demo/Cargo.toml b/demo/Cargo.toml index e3d85b4..b1e5f0f 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen-rayon = { path = "..", optional = true } wasm-bindgen = { workspace = true } -rayon = { workspace = true, optional = true } +rayon = { workspace = true } num-complex = "0.4.0" once_cell = "1.7.2" getrandom = { version = "0.2.2", features = ["js"] } @@ -19,4 +19,4 @@ rand = "0.8.3" hsl = "0.1.1" [features] -parallel = ["rayon", "wasm-bindgen-rayon"] +parallel = ["wasm-bindgen-rayon"] diff --git a/demo/src/lib.rs b/demo/src/lib.rs index 20bb811..d3a393b 100644 --- a/demo/src/lib.rs +++ b/demo/src/lib.rs @@ -13,10 +13,8 @@ use hsl::HSL; use num_complex::Complex64; use rand::Rng; -use wasm_bindgen::{prelude::*, Clamped}; - -#[cfg(feature = "parallel")] use rayon::prelude::*; +use wasm_bindgen::{prelude::*, Clamped}; #[cfg(feature = "parallel")] pub use wasm_bindgen_rayon::init_thread_pool; @@ -74,19 +72,13 @@ impl Generator { .copied() } - // Multi-threaded implementation. - #[cfg(feature = "rayon")] fn iter_bytes(&self) -> impl '_ + ParallelIterator { (0..self.height) + // Note: when built without atomics, into_par_iter() will + // automatically fall back to single-threaded mode. .into_par_iter() .flat_map_iter(move |y| self.iter_row_bytes(y)) } - - // Single-threaded implementation. - #[cfg(not(feature = "rayon"))] - fn iter_bytes(&self) -> impl '_ + Iterator { - (0..self.height).flat_map(move |y| self.iter_row_bytes(y)) - } } #[wasm_bindgen]