servo: Merge #16239 - Remove a memory allocation (iter.collect::<Vec<_>>()) in cascade() (from servo:cascade-collect); r=emilio

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.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: a5a5abd9f4c8a0a9f0b99f8cefcc12151e537d3e

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 561be88a6d42949eaa888ac1293badd2279db565
This commit is contained in:
Simon Sapin 2017-04-03 05:35:19 -05:00
parent a4d0b0a000
commit 1cb213c02c

View File

@ -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 = || {
declaration_blocks.iter().flat_map(|&(ref source, source_importance)| {
source.declarations().iter()
// Yield declarations later in source order (with more precedence) first.
.rev()
.filter_map(move |&(ref declaration, declaration_importance)| {
if declaration_importance == source_importance {
Some(declaration)
} else {
None
}
})
rule_node.self_and_ancestors().flat_map(|node| {
let declarations = match node.style_source() {
Some(source) => source.read(node.cascade_level().guard(guards)).declarations(),
// The root node has no style source.
None => &[]
};
let node_importance = node.importance();
declarations
.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,