style: Optimize serialization of identifiers of length <= 16 🐉🐲

Much like we optimize to_ascii_lowercase.

This also fixes a bug in Servo where attr() rules with an unknown namespace
prefix are parsed, which is wrong.
This commit is contained in:
Emilio Cobos Álvarez 2018-02-07 15:14:10 +01:00
parent e57319a734
commit f4c9c598a3
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
13 changed files with 96 additions and 65 deletions

View file

@ -33,6 +33,25 @@ define_keyword_type!(None_, "none");
define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal");
/// Serialize an identifier which is represented as an atom.
#[cfg(feature = "gecko")]
pub fn serialize_atom_identifier<W>(ident: &Atom, dest: &mut W) -> fmt::Result
where
W: Write,
{
ident.with_str(|s| serialize_identifier(s, dest))
}
/// Serialize an identifier which is represented as an atom.
#[cfg(feature = "servo")]
pub fn serialize_atom_identifier<Static, W>(ident: &::string_cache::Atom<Static>, dest: &mut W) -> fmt::Result
where
Static: ::string_cache::StaticAtomSet,
W: Write,
{
serialize_identifier(&ident, dest)
}
/// Serialize a normalized value into percentage.
pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut CssWriter<W>) -> fmt::Result
where
@ -114,7 +133,7 @@ impl ToCss for CustomIdent {
where
W: Write,
{
serialize_identifier(&self.0.to_string(), dest)
serialize_atom_identifier(&self.0, dest)
}
}