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).
This commit is contained in:
Emilio Cobos Álvarez 2018-02-20 10:05:58 +01:00
parent c676b52448
commit e46f910b66
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 18 additions and 14 deletions

View file

@ -426,7 +426,7 @@ impl PropertyDeclarationBlock {
let all_shorthand_len = match drain.all_shorthand { let all_shorthand_len = match drain.all_shorthand {
AllShorthand::NotSet => 0, AllShorthand::NotSet => 0,
AllShorthand::CSSWideKeyword(_) | AllShorthand::CSSWideKeyword(_) |
AllShorthand::WithVariables(_) => ShorthandId::All.longhands().len() AllShorthand::WithVariables(_) => shorthands::ALL_SHORTHAND_MAX_LEN,
}; };
let push_calls_count = let push_calls_count =
drain.declarations.len() + all_shorthand_len; drain.declarations.len() + all_shorthand_len;
@ -784,8 +784,6 @@ impl PropertyDeclarationBlock {
// Step 3.3.2 // Step 3.3.2
for &shorthand in declaration.shorthands() { for &shorthand in declaration.shorthands() {
let properties = shorthand.longhands();
// Substep 2 & 3 // Substep 2 & 3
let mut current_longhands = SmallVec::<[_; 10]>::new(); let mut current_longhands = SmallVec::<[_; 10]>::new();
let mut important_count = 0; let mut important_count = 0;
@ -811,21 +809,24 @@ impl PropertyDeclarationBlock {
} }
} }
} else { } else {
for (longhand, importance) in self.declaration_importance_iter() { let mut contains_all_longhands = true;
if longhand.id().is_longhand_of(shorthand) { for &longhand in shorthand.longhands() {
current_longhands.push(longhand); match self.get(PropertyDeclarationId::Longhand(longhand)) {
if importance.important() { Some((declaration, importance)) => {
important_count += 1; current_longhands.push(declaration);
if importance.important() {
important_count += 1;
}
}
None => {
contains_all_longhands = false;
break;
} }
} }
} }
// Substep 1: // Substep 1:
// if !contains_all_longhands {
// 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() {
continue; continue;
} }
} }

View file

@ -193,6 +193,9 @@ pub mod shorthands {
spec="https://drafts.csswg.org/css-cascade-3/#all-shorthand" 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)};
} }
<% <%