Avoid memmoving ValidationData more than necessary.

MozReview-Commit-ID: 70w3bZ2FU0W
This commit is contained in:
Bobby Holley 2017-09-11 13:54:28 -07:00
parent 74b4f95d71
commit 8268217767
2 changed files with 8 additions and 5 deletions

View file

@ -393,10 +393,10 @@ impl<Candidate> SharingCacheBase<Candidate> {
} }
impl<E: TElement> SharingCache<E> { impl<E: TElement> SharingCache<E> {
fn insert(&mut self, el: E, validation_data: ValidationData) { fn insert(&mut self, el: E, validation_data_holder: &mut StyleSharingTarget<E>) {
self.entries.insert(StyleSharingCandidate { self.entries.insert(StyleSharingCandidate {
element: el, element: el,
validation_data: validation_data, validation_data: validation_data_holder.take_validation_data(),
}); });
} }
@ -495,10 +495,13 @@ impl<E: TElement> StyleSharingCache<E> {
/// Tries to insert an element in the style sharing cache. /// Tries to insert an element in the style sharing cache.
/// ///
/// Fails if we know it should never be in the cache. /// Fails if we know it should never be in the cache.
///
/// NB: We pass a source for the validation data, rather than the data itself,
/// to avoid memmoving at each function call. See rust issue #42763.
pub fn insert_if_possible(&mut self, pub fn insert_if_possible(&mut self,
element: &E, element: &E,
style: &ComputedValues, style: &ComputedValues,
validation_data: ValidationData, validation_data_holder: &mut StyleSharingTarget<E>,
dom_depth: usize) { dom_depth: usize) {
let parent = match element.traversal_parent() { let parent = match element.traversal_parent() {
Some(element) => element, Some(element) => element,
@ -551,7 +554,7 @@ impl<E: TElement> StyleSharingCache<E> {
self.clear(); self.clear();
self.dom_depth = dom_depth; self.dom_depth = dom_depth;
} }
self.cache_mut().insert(*element, validation_data); self.cache_mut().insert(*element, validation_data_holder);
} }
/// Clear the style sharing candidate cache. /// Clear the style sharing candidate cache.

View file

@ -679,7 +679,7 @@ where
.insert_if_possible( .insert_if_possible(
&element, &element,
new_styles.primary(), new_styles.primary(),
target.take_validation_data(), &mut target,
context.thread_local.bloom_filter.matching_depth(), context.thread_local.bloom_filter.matching_depth(),
); );