aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/gecko/selector_parser.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2020-11-22 01:02:22 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-02-26 16:44:05 +0100
commit9f40b9ba38a531088c2117b955f40af6ea0d09c8 (patch)
treee221662df58ec16b2c2027d71fd5df015fe3f526 /components/style/gecko/selector_parser.rs
parent4ea378a6ae232af09135b2037c527466ef5454de (diff)
downloadservo-9f40b9ba38a531088c2117b955f40af6ea0d09c8.tar.gz
servo-9f40b9ba38a531088c2117b955f40af6ea0d09c8.zip
style: Avoid some allocations in selector serialization.
The allocations in display_to_css_identifier show up in the profiles of bug 1675628. Differential Revision: https://phabricator.services.mozilla.com/D97856
Diffstat (limited to 'components/style/gecko/selector_parser.rs')
-rw-r--r--components/style/gecko/selector_parser.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs
index 6f8ac010e11..c63bc81c95b 100644
--- a/components/style/gecko/selector_parser.rs
+++ b/components/style/gecko/selector_parser.rs
@@ -11,7 +11,7 @@ use crate::invalidation::element::document_state::InvalidationMatchingData;
use crate::selector_parser::{Direction, SelectorParser};
use crate::str::starts_with_ignore_ascii_case;
use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
-use crate::values::serialize_atom_identifier;
+use crate::values::{AtomIdent, AtomString};
use cssparser::{BasicParseError, BasicParseErrorKind, Parser};
use cssparser::{CowRcStr, SourceLocation, ToCss, Token};
use selectors::parser::{SelectorParseErrorKind, ParseErrorRecovery};
@@ -39,7 +39,7 @@ bitflags! {
}
/// The type used to store the language argument to the `:lang` pseudo-class.
-pub type Lang = Atom;
+pub type Lang = AtomIdent;
macro_rules! pseudo_class_name {
([$(($css:expr, $name:ident, $state:tt, $flags:tt),)*]) => {
@@ -77,7 +77,7 @@ impl ToCss for NonTSPseudoClass {
$(NonTSPseudoClass::$name => concat!(":", $css),)*
NonTSPseudoClass::Lang(ref s) => {
dest.write_str(":lang(")?;
- serialize_atom_identifier(s, dest)?;
+ s.to_css(dest)?;
return dest.write_char(')');
},
NonTSPseudoClass::MozLocaleDir(ref dir) => {
@@ -270,12 +270,10 @@ pub struct SelectorImpl;
impl ::selectors::SelectorImpl for SelectorImpl {
type ExtraMatchingData = InvalidationMatchingData;
- type AttrValue = Atom;
- type Identifier = Atom;
- type ClassName = Atom;
- type PartName = Atom;
- type LocalName = Atom;
- type NamespacePrefix = Atom;
+ type AttrValue = AtomString;
+ type Identifier = AtomIdent;
+ type LocalName = AtomIdent;
+ type NamespacePrefix = AtomIdent;
type NamespaceUrl = Namespace;
type BorrowedNamespaceUrl = WeakNamespace;
type BorrowedLocalName = WeakAtom;
@@ -386,7 +384,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
let pseudo_class = match_ignore_ascii_case! { &name,
"lang" => {
let name = parser.expect_ident_or_string()?;
- NonTSPseudoClass::Lang(Atom::from(name.as_ref()))
+ NonTSPseudoClass::Lang(Lang::from(name.as_ref()))
},
"-moz-locale-dir" => {
NonTSPseudoClass::MozLocaleDir(Direction::parse(parser)?)
@@ -475,7 +473,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
self.namespaces.default.clone()
}
- fn namespace_for_prefix(&self, prefix: &Atom) -> Option<Namespace> {
+ fn namespace_for_prefix(&self, prefix: &AtomIdent) -> Option<Namespace> {
self.namespaces.prefixes.get(prefix).cloned()
}
}