From 3fe28e380c8b12fc2266bacf578d0b8f1cb87830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 8 Dec 2017 21:21:49 +0100 Subject: [PATCH] style: Don't unconditionally extend() the declaration block vector. Since it appears in profiles when used from CSSOM, like the one in the bug mentioned in the comment. --- .../style/properties/declaration_block.rs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index f27c2c357ca..788d39c4b48 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -399,15 +399,28 @@ impl PropertyDeclarationBlock { importance: Importance, source: DeclarationSource, ) -> bool { - let all_shorthand_len = match drain.all_shorthand { - AllShorthand::NotSet => 0, - AllShorthand::CSSWideKeyword(_) | - AllShorthand::WithVariables(_) => ShorthandId::All.longhands().len() - }; - let push_calls_count = drain.declarations.len() + all_shorthand_len; + match source { + DeclarationSource::Parsing => { + let all_shorthand_len = match drain.all_shorthand { + AllShorthand::NotSet => 0, + AllShorthand::CSSWideKeyword(_) | + AllShorthand::WithVariables(_) => ShorthandId::All.longhands().len() + }; + let push_calls_count = + drain.declarations.len() + all_shorthand_len; - // With deduplication the actual length increase may be less than this. - self.declarations.reserve(push_calls_count); + // With deduplication the actual length increase may be less than this. + self.declarations.reserve(push_calls_count); + } + DeclarationSource::CssOm => { + // Don't bother reserving space, since it's usually the case + // that CSSOM just overrides properties and we don't need to use + // more memory. See bug 1424346 for an example where this + // matters. + // + // TODO: Would it be worth to call reserve() just if it's empty? + } + } let mut changed = false; for decl in &mut drain.declarations {