From e46f910b66332c2d0726db360afeb5b07c4e91e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 20 Feb 2018 10:05:58 +0100 Subject: [PATCH] style: Rejigger serialization of a declaration block to not look at the shorthands length. This is because I'm going to make shorthands() and longhands() return an iterator, so that we account for prefs properly (https://bugzilla.mozilla.org/show_bug.cgi?id=1438234). --- .../style/properties/declaration_block.rs | 29 ++++++++++--------- .../style/properties/properties.mako.rs | 3 ++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 9530a5aca7e..03485db9bf0 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -426,7 +426,7 @@ impl PropertyDeclarationBlock { let all_shorthand_len = match drain.all_shorthand { AllShorthand::NotSet => 0, AllShorthand::CSSWideKeyword(_) | - AllShorthand::WithVariables(_) => ShorthandId::All.longhands().len() + AllShorthand::WithVariables(_) => shorthands::ALL_SHORTHAND_MAX_LEN, }; let push_calls_count = drain.declarations.len() + all_shorthand_len; @@ -784,8 +784,6 @@ impl PropertyDeclarationBlock { // Step 3.3.2 for &shorthand in declaration.shorthands() { - let properties = shorthand.longhands(); - // Substep 2 & 3 let mut current_longhands = SmallVec::<[_; 10]>::new(); let mut important_count = 0; @@ -811,21 +809,24 @@ impl PropertyDeclarationBlock { } } } else { - for (longhand, importance) in self.declaration_importance_iter() { - if longhand.id().is_longhand_of(shorthand) { - current_longhands.push(longhand); - if importance.important() { - important_count += 1; + let mut contains_all_longhands = true; + for &longhand in shorthand.longhands() { + match self.get(PropertyDeclarationId::Longhand(longhand)) { + Some((declaration, importance)) => { + current_longhands.push(declaration); + if importance.important() { + important_count += 1; + } + } + None => { + contains_all_longhands = false; + break; } } } + // Substep 1: - // - // Assuming that the PropertyDeclarationBlock contains no - // duplicate entries, if the current_longhands length is - // equal to the properties length, it means that the - // properties that map to shorthand are present in longhands - if current_longhands.len() != properties.len() { + if !contains_all_longhands { continue; } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 523bfc4de31..0b3112006e9 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -193,6 +193,9 @@ pub mod shorthands { spec="https://drafts.csswg.org/css-cascade-3/#all-shorthand" ) %> + + /// The max amount of longhands that the `all` shorthand will ever contain. + pub const ALL_SHORTHAND_MAX_LEN: usize = ${len(logical_longhands + other_longhands)}; } <%