mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
style: Shrink selectors::Component to 24 bytes.
This saves about 37 KiB of memory across the UA style sheets. Bug: 1475197 Reviewed-by: emilio
This commit is contained in:
parent
b05ace3e4a
commit
62419adaaa
12 changed files with 96 additions and 50 deletions
|
@ -15,6 +15,7 @@ use properties::longhands::display::computed_value::T as Display;
|
|||
use selector_parser::{NonTSPseudoClass, PseudoElementCascadeType, SelectorImpl};
|
||||
use std::fmt;
|
||||
use string_cache::Atom;
|
||||
use thin_slice::ThinBoxedSlice;
|
||||
use values::serialize_atom_identifier;
|
||||
|
||||
include!(concat!(
|
||||
|
|
|
@ -8,7 +8,7 @@ pub enum PseudoElement {
|
|||
% for pseudo in PSEUDOS:
|
||||
/// ${pseudo.value}
|
||||
% if pseudo.is_tree_pseudo_element():
|
||||
${pseudo.capitalized()}(Box<[Atom]>),
|
||||
${pseudo.capitalized()}(ThinBoxedSlice<Atom>),
|
||||
% else:
|
||||
${pseudo.capitalized()},
|
||||
% endif
|
||||
|
@ -209,7 +209,7 @@ impl PseudoElement {
|
|||
% for pseudo in PSEUDOS:
|
||||
% if pseudo.is_tree_pseudo_element():
|
||||
if atom == &atom!("${pseudo.value}") {
|
||||
return Some(PseudoElement::${pseudo.capitalized()}(args));
|
||||
return Some(PseudoElement::${pseudo.capitalized()}(args.into()));
|
||||
}
|
||||
% endif
|
||||
% endfor
|
||||
|
@ -256,7 +256,7 @@ impl PseudoElement {
|
|||
let tree_part = &name[10..];
|
||||
% for pseudo in TREE_PSEUDOS:
|
||||
if tree_part.eq_ignore_ascii_case("${pseudo.value[11:]}") {
|
||||
return Some(${pseudo_element_variant(pseudo, "args")});
|
||||
return Some(${pseudo_element_variant(pseudo, "args.into()")});
|
||||
}
|
||||
% endfor
|
||||
None
|
||||
|
|
|
@ -13,11 +13,13 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
|||
use invalidation::element::document_state::InvalidationMatchingData;
|
||||
use selector_parser::{Direction, SelectorParser};
|
||||
use selectors::SelectorList;
|
||||
use selectors::parser::{self as selector_parser, Selector, SelectorParseErrorKind, Visit};
|
||||
use selectors::parser::{self as selector_parser, Selector};
|
||||
use selectors::parser::{SelectorParseErrorKind, Visit};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use std::fmt;
|
||||
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss as ToCss_};
|
||||
use thin_slice::ThinBoxedSlice;
|
||||
|
||||
pub use gecko::pseudo_element::{PseudoElement, EAGER_PSEUDOS, EAGER_PSEUDO_COUNT, PSEUDO_COUNT};
|
||||
pub use gecko::snapshot::SnapshotMap;
|
||||
|
@ -34,7 +36,7 @@ bitflags! {
|
|||
}
|
||||
|
||||
/// The type used for storing pseudo-class string arguments.
|
||||
pub type PseudoClassStringArg = Box<[u16]>;
|
||||
pub type PseudoClassStringArg = ThinBoxedSlice<u16>;
|
||||
|
||||
macro_rules! pseudo_class_name {
|
||||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||
|
@ -56,7 +58,7 @@ macro_rules! pseudo_class_name {
|
|||
///
|
||||
/// TODO(emilio): We disallow combinators and pseudos here, so we
|
||||
/// should use SimpleSelector instead
|
||||
MozAny(Box<[Selector<SelectorImpl>]>),
|
||||
MozAny(ThinBoxedSlice<Selector<SelectorImpl>>),
|
||||
/// The non-standard `:-moz-locale-dir` pseudo-class.
|
||||
MozLocaleDir(Box<Direction>),
|
||||
}
|
||||
|
@ -405,7 +407,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
// 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())
|
||||
NonTSPseudoClass::$s_name(utf16.into_boxed_slice().into())
|
||||
}, )*
|
||||
"-moz-locale-dir" => {
|
||||
NonTSPseudoClass::MozLocaleDir(
|
||||
|
@ -422,7 +424,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
selector_parser::parse_compound_selector_list(
|
||||
self,
|
||||
parser,
|
||||
)?
|
||||
)?.into()
|
||||
)
|
||||
}
|
||||
_ => return Err(parser.new_custom_error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue