Skip to content

Commit

Permalink
Push elements in order in StyleBloom::rebuilds.
Browse files Browse the repository at this point in the history
This is important because we're about to start storing a parallel list
of pushed hashes, and the current behavior here will cause mismatches
there.

We take the opportunity to bump the SmallVec size to 16, since each
entry is only a word and we really want to avoid heap-allocating. And
then we switch to drain(), because of
rust-lang/rust#42763
  • Loading branch information
bholley committed Jun 22, 2017
1 parent ed5485e commit 0f0e0d8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions components/style/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ impl<E: TElement> StyleBloom<E> {
pub fn rebuild(&mut self, mut element: E) {
self.clear();

let mut parents_to_insert = SmallVec::<[E; 16]>::new();
while let Some(parent) = element.traversal_parent() {
self.push_internal(parent);
parents_to_insert.push(parent);
element = parent;
}

// Put them in the order we expect, from root to `element`'s parent.
self.elements.reverse();
for parent in parents_to_insert.drain().rev() {
self.push(parent);
}
}

/// In debug builds, asserts that all the parents of `element` are in the
Expand Down Expand Up @@ -238,7 +240,7 @@ impl<E: TElement> StyleBloom<E> {

// Let's collect the parents we are going to need to insert once we've
// found the common one.
let mut parents_to_insert = SmallVec::<[E; 8]>::new();
let mut parents_to_insert = SmallVec::<[E; 16]>::new();

// If the bloom filter still doesn't have enough elements, the common
// parent is up in the dom.
Expand Down Expand Up @@ -284,7 +286,7 @@ impl<E: TElement> StyleBloom<E> {

// Now the parents match, so insert the stack of elements we have been
// collecting so far.
for parent in parents_to_insert.into_iter().rev() {
for parent in parents_to_insert.drain().rev() {
self.push(parent);
}

Expand Down

0 comments on commit 0f0e0d8

Please sign in to comment.