mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Remove a memory allocation (iter.collect::<Vec<_>>()
) in cascade()
This vector was there to pre-acquire locks and give all declarations the same lifetime (which is necessary for custom properties cascading). https://github.com/servo/servo/pull/16014 introduce a guard to a shared pre-acquired lock, making this vector unnecessary.
This commit is contained in:
parent
5b037a0aa0
commit
510bcc6186
1 changed files with 18 additions and 17 deletions
|
@ -1976,24 +1976,25 @@ pub fn cascade(device: &Device,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hold locks until after the apply_declarations() call returns.
|
|
||||||
// Use filter_map because the root node has no style source.
|
|
||||||
let declaration_blocks = rule_node.self_and_ancestors().filter_map(|node| {
|
|
||||||
let guard = node.cascade_level().guard(guards);
|
|
||||||
node.style_source().map(|source| (source.read(guard), node.importance()))
|
|
||||||
}).collect::<Vec<_>>();
|
|
||||||
let iter_declarations = || {
|
let iter_declarations = || {
|
||||||
declaration_blocks.iter().flat_map(|&(ref source, source_importance)| {
|
rule_node.self_and_ancestors().flat_map(|node| {
|
||||||
source.declarations().iter()
|
let declarations = match node.style_source() {
|
||||||
// Yield declarations later in source order (with more precedence) first.
|
Some(source) => source.read(node.cascade_level().guard(guards)).declarations(),
|
||||||
.rev()
|
// The root node has no style source.
|
||||||
.filter_map(move |&(ref declaration, declaration_importance)| {
|
None => &[]
|
||||||
if declaration_importance == source_importance {
|
};
|
||||||
Some(declaration)
|
let node_importance = node.importance();
|
||||||
} else {
|
declarations
|
||||||
None
|
.iter()
|
||||||
}
|
// Yield declarations later in source order (with more precedence) first.
|
||||||
})
|
.rev()
|
||||||
|
.filter_map(move |&(ref declaration, declaration_importance)| {
|
||||||
|
if declaration_importance == node_importance {
|
||||||
|
Some(declaration)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
apply_declarations(device,
|
apply_declarations(device,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue