phase 7.2/7.4: add compute_batch and matching_rules_batch for parallel style processing
This commit is contained in:
@@ -689,6 +689,36 @@ impl StyleSheet {
|
||||
Some(props)
|
||||
}
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
pub fn matching_rules_batch<'a>(
|
||||
&'a self,
|
||||
type_names: &[&str],
|
||||
el_ids: &[Option<&str>],
|
||||
el_classes_list: &[&[&str]],
|
||||
active_pseudo_list: &[&[&str]],
|
||||
structural_list: &[&StructuralContext],
|
||||
ancestors_list: &[&[AncestorInfo]],
|
||||
preceding_siblings_list: &[&[AncestorInfo]],
|
||||
el_attributes_list: &[&HashMap<String, String>],
|
||||
) -> Vec<Vec<&'a HashMap<String, String>>> {
|
||||
use rayon::prelude::*;
|
||||
(0..type_names.len())
|
||||
.into_par_iter()
|
||||
.map(|i| {
|
||||
self.matching_rules(
|
||||
type_names[i],
|
||||
el_ids[i],
|
||||
el_classes_list[i],
|
||||
active_pseudo_list[i],
|
||||
structural_list[i],
|
||||
ancestors_list[i],
|
||||
preceding_siblings_list[i],
|
||||
el_attributes_list[i],
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn matching_pseudo_rules(
|
||||
&self,
|
||||
pseudo: &str,
|
||||
@@ -951,6 +981,14 @@ let overflow = lookup("overflow", inline, matched_sheets).and_then(parse_overflo
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
pub fn compute_batch<'a>(
|
||||
pairs: &[(&[(Cow<'_, str>, Cow<'_, str>)], &[&'a HashMap<String, String>])],
|
||||
) -> Vec<ComputedStyle> {
|
||||
use rayon::prelude::*;
|
||||
pairs.par_iter().map(|(inline, sheets)| Self::compute(inline, sheets)).collect()
|
||||
}
|
||||
|
||||
pub fn apply_overrides(&mut self, sheet: &HashMap<String, String>) {
|
||||
struct Override<'a>(&'a HashMap<String, String>);
|
||||
impl<'a> Override<'a> {
|
||||
|
||||
Reference in New Issue
Block a user