Skip to content

Commit

Permalink
style: Use an Atom to store pseudo-class string arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
heycam authored and emilio committed Sep 3, 2018
1 parent 4ee3b56 commit 2af9264
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
20 changes: 3 additions & 17 deletions components/style/gecko/selector_parser.rs
Expand Up @@ -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),)*],
Expand Down Expand Up @@ -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(")?;
Expand Down Expand Up @@ -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)?)
Expand Down
6 changes: 1 addition & 5 deletions components/style/gecko/wrapper.rs
Expand Up @@ -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(),
Expand All @@ -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(),
)
}
}
Expand Down

0 comments on commit 2af9264

Please sign in to comment.