diff options
author | Cameron McCormack <cam@mcc.id.au> | 2018-08-31 17:05:56 +1000 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-09-03 12:33:24 +0200 |
commit | 2af9264cfe00701d7672e441ef63363a35da85b7 (patch) | |
tree | 7baacaf6aa970193fefb6ae76cbb9ebbbca8b2cc | |
parent | 4ee3b56d549eec83a312dc048476b1bebabb9a39 (diff) | |
download | servo-2af9264cfe00701d7672e441ef63363a35da85b7.tar.gz servo-2af9264cfe00701d7672e441ef63363a35da85b7.zip |
style: Use an Atom to store pseudo-class string arguments.
Differential Revision: https://phabricator.services.mozilla.com/D4740
-rw-r--r-- | components/style/gecko/selector_parser.rs | 20 | ||||
-rw-r--r-- | components/style/gecko/wrapper.rs | 6 |
2 files changed, 4 insertions, 22 deletions
diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index e9652b8386f..dcdb06e466a 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -37,7 +37,7 @@ bitflags! { } /// The type used for storing pseudo-class string arguments. -pub type PseudoClassStringArg = ThinBoxedSlice<u16>; +pub type PseudoClassStringArg = Atom; macro_rules! pseudo_class_name { (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], @@ -72,24 +72,13 @@ impl ToCss for NonTSPseudoClass { where W: fmt::Write, { - use cssparser::CssStringWriter; - use std::fmt::Write; macro_rules! pseudo_class_serialize { (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*]) => { match *self { $(NonTSPseudoClass::$name => concat!(":", $css),)* $(NonTSPseudoClass::$s_name(ref s) => { - dest.write_str(concat!(":", $s_css, "("))?; - { - // FIXME(emilio): Avoid the extra allocation! - let mut css = CssStringWriter::new(dest); - - // Discount the null char in the end from the - // string. - css.write_str(&String::from_utf16(&s[..s.len() - 1]).unwrap())?; - } - return dest.write_str(")") + return write!(dest, concat!(":", $s_css, "({})"), s) }, )* NonTSPseudoClass::MozLocaleDir(ref dir) => { dest.write_str(":-moz-locale-dir(")?; @@ -405,10 +394,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { match_ignore_ascii_case! { &name, $($s_css => { let name = parser.expect_ident_or_string()?; - // convert to null terminated utf16 string - // since that's what Gecko deals with - let utf16: Vec<u16> = name.encode_utf16().chain(Some(0u16)).collect(); - NonTSPseudoClass::$s_name(utf16.into_boxed_slice().into()) + NonTSPseudoClass::$s_name(Atom::from(name.as_ref())) }, )* "-moz-locale-dir" => { NonTSPseudoClass::MozLocaleDir(Direction::parse(parser)?) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 914bdad852b..031a9f40fdd 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1721,10 +1721,6 @@ impl<'le> TElement for GeckoElement<'le> { // Gecko supports :lang() from CSS Selectors 3, which only accepts a // single language tag, and which performs simple dash-prefix matching // on it. - debug_assert!( - value.len() > 0 && value[value.len() - 1] == 0, - "expected value to be null terminated" - ); let override_lang_ptr = match &override_lang { &Some(Some(ref atom)) => atom.as_ptr(), _ => ptr::null_mut(), @@ -1734,7 +1730,7 @@ impl<'le> TElement for GeckoElement<'le> { self.0, override_lang_ptr, override_lang.is_some(), - value.as_ptr(), + value.as_slice().as_ptr(), ) } } |