style: Avoid useless allocations in custom property name serialization.

And make transition-property more correct by serializing --0 unescaped instead
of escaped.

Bug: 1466645
Reviewed-by: xidorn
MozReview-Commit-ID: CCBSe5Frd0d
This commit is contained in:
Emilio Cobos Álvarez 2018-06-05 15:53:43 +02:00
parent 63ca2a803d
commit c6e43c0329
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 32 additions and 7 deletions

View file

@ -49,6 +49,7 @@ use stylesheets::{CssRuleType, Origin, UrlExtraData};
use values::generics::text::LineHeight; use values::generics::text::LineHeight;
use values::computed; use values::computed;
use values::computed::NonNegativeLength; use values::computed::NonNegativeLength;
use values::serialize_atom_name;
use rule_tree::{CascadeLevel, StrongRuleNode}; use rule_tree::{CascadeLevel, StrongRuleNode};
use self::computed_value_flags::*; use self::computed_value_flags::*;
use str::{CssString, CssStringBorrow, CssStringWriter}; use str::{CssString, CssStringBorrow, CssStringWriter};
@ -1506,8 +1507,9 @@ impl<'a> ToCss for PropertyDeclarationId<'a> {
{ {
match *self { match *self {
PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()), PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()),
PropertyDeclarationId::Custom(_) => { PropertyDeclarationId::Custom(ref name) => {
serialize_identifier(&self.name(), dest) dest.write_str("--")?;
serialize_atom_name(name, dest)
} }
} }
} }
@ -1587,8 +1589,9 @@ impl ToCss for PropertyId {
PropertyId::Shorthand(id) => dest.write_str(id.name()), PropertyId::Shorthand(id) => dest.write_str(id.name()),
PropertyId::LonghandAlias(id, _) => dest.write_str(id.name()), PropertyId::LonghandAlias(id, _) => dest.write_str(id.name()),
PropertyId::ShorthandAlias(id, _) => dest.write_str(id.name()), PropertyId::ShorthandAlias(id, _) => dest.write_str(id.name()),
PropertyId::Custom(_) => { PropertyId::Custom(ref name) => {
serialize_identifier(&self.name(), dest) dest.write_str("--")?;
serialize_atom_name(name, dest)
} }
} }
} }

View file

@ -9,7 +9,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use Atom; use Atom;
pub use cssparser::{serialize_identifier, CowRcStr, Parser, SourceLocation, Token, RGBA}; pub use cssparser::{serialize_identifier, serialize_name, CowRcStr, Parser, SourceLocation, Token, RGBA};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind; use selectors::parser::SelectorParseErrorKind;
use std::fmt::{self, Debug, Write}; use std::fmt::{self, Debug, Write};
@ -60,6 +60,28 @@ where
serialize_identifier(&ident, dest) serialize_identifier(&ident, dest)
} }
/// Serialize a name which is represented as an Atom.
#[cfg(feature = "gecko")]
pub fn serialize_atom_name<W>(ident: &Atom, dest: &mut W) -> fmt::Result
where
W: Write,
{
ident.with_str(|s| serialize_name(s, dest))
}
/// Serialize a name which is represented as an Atom.
#[cfg(feature = "servo")]
pub fn serialize_atom_name<Static, W>(
ident: &::string_cache::Atom<Static>,
dest: &mut W,
) -> fmt::Result
where
Static: ::string_cache::StaticAtomSet,
W: Write,
{
serialize_name(&ident, dest)
}
/// Serialize a normalized value into percentage. /// Serialize a normalized value into percentage.
pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut CssWriter<W>) -> fmt::Result pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut CssWriter<W>) -> fmt::Result
where where

View file

@ -756,13 +756,13 @@ impl ToCss for TransitionProperty {
where where
W: Write, W: Write,
{ {
use values::serialize_atom_identifier; use values::serialize_atom_name;
match *self { match *self {
TransitionProperty::Shorthand(ref s) => s.to_css(dest), TransitionProperty::Shorthand(ref s) => s.to_css(dest),
TransitionProperty::Longhand(ref l) => l.to_css(dest), TransitionProperty::Longhand(ref l) => l.to_css(dest),
TransitionProperty::Custom(ref name) => { TransitionProperty::Custom(ref name) => {
dest.write_str("--")?; dest.write_str("--")?;
serialize_atom_identifier(name, dest) serialize_atom_name(name, dest)
} }
TransitionProperty::Unsupported(ref i) => i.to_css(dest), TransitionProperty::Unsupported(ref i) => i.to_css(dest),
} }