mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: There's no need to check the serialized custom properties.
Given they're not duplicated, and can't be part of a shorthand.
This commit is contained in:
parent
4c979a8346
commit
c09257b540
2 changed files with 46 additions and 67 deletions
|
@ -761,20 +761,40 @@ impl PropertyDeclarationBlock {
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block
|
/// https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block
|
||||||
pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result {
|
pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result {
|
||||||
|
use std::iter::Cloned;
|
||||||
|
use std::slice;
|
||||||
|
|
||||||
let mut is_first_serialization = true; // trailing serializations should have a prepended space
|
let mut is_first_serialization = true; // trailing serializations should have a prepended space
|
||||||
|
|
||||||
// Step 1 -> dest = result list
|
// Step 1 -> dest = result list
|
||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
let mut already_serialized = PropertyDeclarationIdSet::new();
|
let mut already_serialized_longhands = LonghandIdSet::new();
|
||||||
|
|
||||||
// Step 3
|
// Step 3
|
||||||
for (declaration, importance) in self.declaration_importance_iter() {
|
for (declaration, importance) in self.declaration_importance_iter() {
|
||||||
// Step 3.1
|
// Step 3.1
|
||||||
let property = declaration.id();
|
let property = declaration.id();
|
||||||
|
let longhand_id = match property {
|
||||||
|
PropertyDeclarationId::Longhand(id) => id,
|
||||||
|
PropertyDeclarationId::Custom(..) => {
|
||||||
|
// Given the invariants that there are no duplicate
|
||||||
|
// properties in a declaration block, and that custom
|
||||||
|
// properties can't be part of a shorthand, we can just care
|
||||||
|
// about them here.
|
||||||
|
append_serialization::<Cloned<slice::Iter< _>>, _>(
|
||||||
|
dest,
|
||||||
|
&property,
|
||||||
|
AppendableValue::Declaration(declaration),
|
||||||
|
importance,
|
||||||
|
&mut is_first_serialization,
|
||||||
|
)?;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Step 3.2
|
// Step 3.2
|
||||||
if already_serialized.contains(property) {
|
if already_serialized_longhands.contains(longhand_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,7 +803,7 @@ impl PropertyDeclarationBlock {
|
||||||
// iterating below.
|
// iterating below.
|
||||||
|
|
||||||
// Step 3.3.2
|
// Step 3.3.2
|
||||||
for &shorthand in declaration.shorthands() {
|
for &shorthand in longhand_id.shorthands() {
|
||||||
// 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;
|
||||||
|
@ -792,8 +812,19 @@ impl PropertyDeclarationBlock {
|
||||||
let is_system_font =
|
let is_system_font =
|
||||||
shorthand == ShorthandId::Font &&
|
shorthand == ShorthandId::Font &&
|
||||||
self.declarations.iter().any(|l| {
|
self.declarations.iter().any(|l| {
|
||||||
!already_serialized.contains(l.id()) &&
|
match l.id() {
|
||||||
l.get_system().is_some()
|
PropertyDeclarationId::Longhand(id) => {
|
||||||
|
if already_serialized_longhands.contains(id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
l.get_system().is_some()
|
||||||
|
}
|
||||||
|
PropertyDeclarationId::Custom(..) => {
|
||||||
|
debug_assert!(l.get_system().is_none());
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if is_system_font {
|
if is_system_font {
|
||||||
|
@ -894,8 +925,13 @@ impl PropertyDeclarationBlock {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for current_longhand in ¤t_longhands {
|
for current_longhand in ¤t_longhands {
|
||||||
|
let longhand_id = match current_longhand.id() {
|
||||||
|
PropertyDeclarationId::Longhand(id) => id,
|
||||||
|
PropertyDeclarationId::Custom(..) => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
// Substep 9
|
// Substep 9
|
||||||
already_serialized.insert(current_longhand.id());
|
already_serialized_longhands.insert(longhand_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(https://github.com/w3c/csswg-drafts/issues/1774)
|
// FIXME(https://github.com/w3c/csswg-drafts/issues/1774)
|
||||||
|
@ -907,12 +943,10 @@ impl PropertyDeclarationBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.3.4
|
// Step 3.3.4
|
||||||
if already_serialized.contains(property) {
|
if already_serialized_longhands.contains(longhand_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::iter::Cloned;
|
|
||||||
use std::slice;
|
|
||||||
|
|
||||||
// Steps 3.3.5, 3.3.6 & 3.3.7
|
// Steps 3.3.5, 3.3.6 & 3.3.7
|
||||||
// Need to specify an iterator type here even though it’s unused to work around
|
// Need to specify an iterator type here even though it’s unused to work around
|
||||||
|
@ -924,10 +958,11 @@ impl PropertyDeclarationBlock {
|
||||||
&property,
|
&property,
|
||||||
AppendableValue::Declaration(declaration),
|
AppendableValue::Declaration(declaration),
|
||||||
importance,
|
importance,
|
||||||
&mut is_first_serialization)?;
|
&mut is_first_serialization,
|
||||||
|
)?;
|
||||||
|
|
||||||
// Step 3.3.8
|
// Step 3.3.8
|
||||||
already_serialized.insert(property);
|
already_serialized_longhands.insert(longhand_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
|
|
|
@ -688,62 +688,6 @@ impl LonghandIdSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specialized set of PropertyDeclarationId
|
|
||||||
pub struct PropertyDeclarationIdSet {
|
|
||||||
longhands: LonghandIdSet,
|
|
||||||
|
|
||||||
// FIXME: Use a HashSet instead? This Vec is usually small, so linear scan might be ok.
|
|
||||||
custom: Vec<::custom_properties::Name>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PropertyDeclarationIdSet {
|
|
||||||
/// Empty set
|
|
||||||
pub fn new() -> Self {
|
|
||||||
PropertyDeclarationIdSet {
|
|
||||||
longhands: LonghandIdSet::new(),
|
|
||||||
custom: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns all the longhands that this set contains.
|
|
||||||
pub fn longhands(&self) -> &LonghandIdSet {
|
|
||||||
&self.longhands
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether the set is empty.
|
|
||||||
#[inline]
|
|
||||||
pub fn is_empty(&self) -> bool {
|
|
||||||
self.longhands.is_empty() && self.custom.is_empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clears the set.
|
|
||||||
#[inline]
|
|
||||||
pub fn clear(&mut self) {
|
|
||||||
self.longhands.clear();
|
|
||||||
self.custom.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether the given ID is in the set
|
|
||||||
pub fn contains(&mut self, id: PropertyDeclarationId) -> bool {
|
|
||||||
match id {
|
|
||||||
PropertyDeclarationId::Longhand(id) => self.longhands.contains(id),
|
|
||||||
PropertyDeclarationId::Custom(name) => self.custom.contains(name),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert the given ID in the set
|
|
||||||
pub fn insert(&mut self, id: PropertyDeclarationId) {
|
|
||||||
match id {
|
|
||||||
PropertyDeclarationId::Longhand(id) => self.longhands.insert(id),
|
|
||||||
PropertyDeclarationId::Custom(name) => {
|
|
||||||
if !self.custom.contains(name) {
|
|
||||||
self.custom.push(name.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An enum to represent a CSS Wide keyword.
|
/// An enum to represent a CSS Wide keyword.
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum CSSWideKeyword {
|
pub enum CSSWideKeyword {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue