add remaining rayon, better feature switches
This commit is contained in:
parent
d2ede29165
commit
84a3b182ab
5 changed files with 65 additions and 46 deletions
|
@ -36,6 +36,7 @@ printpdf = { version = "0.8.2", features = [
|
||||||
shiva = "1.4.9"
|
shiva = "1.4.9"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
font-kit = { version = "0.14.2", features = ["loader-freetype-default"] }
|
font-kit = { version = "0.14.2", features = ["loader-freetype-default"] }
|
||||||
|
cfg-if = "1.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
project-root = "0"
|
project-root = "0"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{borrow::Cow, convert::Infallible};
|
use std::{borrow::Cow, convert::Infallible};
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
#[cfg(feature = "rayon")]
|
#[cfg(feature = "rayon")]
|
||||||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
||||||
|
|
||||||
|
@ -28,13 +29,15 @@ impl TryFromDataBytes for Bytes {
|
||||||
|
|
||||||
impl Bendable for Bytes {
|
impl Bendable for Bytes {
|
||||||
type Unit = u8;
|
type Unit = u8;
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||||
self.par_iter_mut().for_each(|e| *e = f(Cow::Borrowed(e)));
|
cfg_if! {
|
||||||
self
|
if #[cfg(feature = "rayon")] {
|
||||||
|
let iter = self.par_iter_mut();
|
||||||
|
} else {
|
||||||
|
let iter = self.iter_mut();
|
||||||
}
|
}
|
||||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
}
|
||||||
self.iter_mut().for_each(|e| *e = f(Cow::Borrowed(e)));
|
iter.for_each(|e| *e = f(Cow::Borrowed(e)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
fn format() -> crate::Format {
|
fn format() -> crate::Format {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use printpdf::{
|
use printpdf::{
|
||||||
Op, PdfDocument, PdfPage, PdfParseErrorSeverity, PdfParseOptions, PdfSaveOptions, PdfWarnMsg,
|
Op, PdfDocument, PdfPage, PdfParseErrorSeverity, PdfParseOptions, PdfSaveOptions, PdfWarnMsg,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
|
|
||||||
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
||||||
|
|
||||||
|
@ -73,9 +76,15 @@ impl Bendable for PdfDocument {
|
||||||
pages: pages
|
pages: pages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|page| PdfPage {
|
.map(|page| PdfPage {
|
||||||
ops: page
|
ops: {
|
||||||
.ops
|
cfg_if! {
|
||||||
.into_iter()
|
if #[cfg(feature = "rayon")] {
|
||||||
|
page.ops.into_par_iter()
|
||||||
|
} else {
|
||||||
|
page.ops.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.map(|op| f(Cow::Owned(op)))
|
.map(|op| f(Cow::Owned(op)))
|
||||||
.collect::<Vec<Op>>(),
|
.collect::<Vec<Op>>(),
|
||||||
..page
|
..page
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
||||||
ops::{Add, Deref, DerefMut, Div, Mul, Sub},
|
ops::{Add, Deref, DerefMut, Div, Mul, Sub},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
pub use image::*;
|
pub use image::*;
|
||||||
use num::{
|
use num::{
|
||||||
traits::{FromBytes, ToBytes},
|
traits::{FromBytes, ToBytes},
|
||||||
|
@ -179,13 +180,15 @@ where
|
||||||
P: Send + Sync,
|
P: Send + Sync,
|
||||||
{
|
{
|
||||||
type Unit = P;
|
type Unit = P;
|
||||||
#[cfg(feature = "rayon")]
|
|
||||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||||
self.par_pixels_mut().for_each(|p| *p = f(Cow::Borrowed(p)));
|
cfg_if! {
|
||||||
self
|
if #[cfg(feature = "rayon")] {
|
||||||
|
let iter = self.par_pixels_mut();
|
||||||
|
} else {
|
||||||
|
let iter = self.pixels_mut();
|
||||||
}
|
}
|
||||||
fn map<F: Fn(Cow<Self::Unit>) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
}
|
||||||
self.pixels_mut().for_each(|p| *p = f(Cow::Borrowed(p)));
|
iter.for_each(|p| *p = f(Cow::Borrowed(p)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
fn format() -> crate::Format {
|
fn format() -> crate::Format {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use super::Sample;
|
use super::Sample;
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use derive_wrapper::{AsRef, From};
|
use derive_wrapper::{AsRef, From};
|
||||||
use num::{
|
use num::{
|
||||||
traits::{FromBytes, ToBytes},
|
traits::{FromBytes, ToBytes},
|
||||||
|
@ -67,7 +68,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rayon")]
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "rayon")] {
|
||||||
impl<T> Bendable for RawSamples<T>
|
impl<T> Bendable for RawSamples<T>
|
||||||
where
|
where
|
||||||
T: Sample + FromBytes + ToBytes + Zero + Send,
|
T: Sample + FromBytes + ToBytes + Zero + Send,
|
||||||
|
@ -83,7 +85,7 @@ where
|
||||||
crate::Format::Sound
|
crate::Format::Sound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
impl<T> Bendable for RawSamples<T>
|
impl<T> Bendable for RawSamples<T>
|
||||||
where
|
where
|
||||||
T: Sample + FromBytes + ToBytes + Zero + Send,
|
T: Sample + FromBytes + ToBytes + Zero + Send,
|
||||||
|
@ -98,3 +100,4 @@ where
|
||||||
crate::Format::Sound
|
crate::Format::Sound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue