mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Do the sequential traversal breadth-first.
While we're at it, we also eliminate the 'unknown' dom depth for the bloom filter. Computing depth has negligible cost relative to the amount of work we do setting up the bloom filter at a given depth. Doing it once per traversal should be totally fine. I originally separated the elimination of unknown dom depth from the traversal changes, but I got bloom filter crashes on the intermediate patch, presumably because I didn't properly fix the sequential traversal for this case. Given that the final state is green, I just decided to squash and move on.
This commit is contained in:
parent
1b363ac909
commit
3f52052cf9
9 changed files with 63 additions and 75 deletions
|
@ -99,7 +99,7 @@ impl<E: TElement> StyleBloom<E> {
|
|||
}
|
||||
|
||||
/// Rebuilds the bloom filter up to the parent of the given element.
|
||||
pub fn rebuild(&mut self, mut element: E) -> usize {
|
||||
pub fn rebuild(&mut self, mut element: E) {
|
||||
self.clear();
|
||||
|
||||
while let Some(parent) = element.parent_element() {
|
||||
|
@ -110,7 +110,6 @@ impl<E: TElement> StyleBloom<E> {
|
|||
|
||||
// Put them in the order we expect, from root to `element`'s parent.
|
||||
self.elements.reverse();
|
||||
return self.elements.len();
|
||||
}
|
||||
|
||||
/// In debug builds, asserts that all the parents of `element` are in the
|
||||
|
@ -139,12 +138,12 @@ impl<E: TElement> StyleBloom<E> {
|
|||
/// responsible to keep around if it wants to get an effective filter.
|
||||
pub fn insert_parents_recovering(&mut self,
|
||||
element: E,
|
||||
element_depth: Option<usize>)
|
||||
-> usize
|
||||
element_depth: usize)
|
||||
{
|
||||
// Easy case, we're in a different restyle, or we're empty.
|
||||
if self.elements.is_empty() {
|
||||
return self.rebuild(element);
|
||||
self.rebuild(element);
|
||||
return;
|
||||
}
|
||||
|
||||
let parent_element = match element.parent_element() {
|
||||
|
@ -152,23 +151,19 @@ impl<E: TElement> StyleBloom<E> {
|
|||
None => {
|
||||
// Yay, another easy case.
|
||||
self.clear();
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if self.elements.last().map(|el| **el) == Some(parent_element) {
|
||||
// Ta da, cache hit, we're all done.
|
||||
return self.elements.len();
|
||||
return;
|
||||
}
|
||||
|
||||
let element_depth = match element_depth {
|
||||
Some(depth) => depth,
|
||||
// If we don't know the depth of `element`, we'd rather don't try
|
||||
// fixing up the bloom filter, since it's quadratic.
|
||||
None => {
|
||||
return self.rebuild(element);
|
||||
}
|
||||
};
|
||||
if element_depth == 0 {
|
||||
self.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// We should've early exited above.
|
||||
debug_assert!(element_depth != 0,
|
||||
|
@ -250,6 +245,5 @@ impl<E: TElement> StyleBloom<E> {
|
|||
debug_assert_eq!(self.elements.len(), element_depth);
|
||||
|
||||
// We're done! Easy.
|
||||
return self.elements.len();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue