mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Remove hashes from style rules and dependencies.
Dependencies are very numerous, and now we shouldn't be getting so many of them. Style rules just don't need them, so it's a waste of memory.
This commit is contained in:
parent
9394ea9644
commit
dee4aea264
8 changed files with 61 additions and 84 deletions
|
@ -164,10 +164,10 @@ pub fn matches_selector_list<E>(selector_list: &SelectorList<E::Impl>,
|
|||
-> bool
|
||||
where E: Element
|
||||
{
|
||||
selector_list.0.iter().any(|selector_and_hashes| {
|
||||
matches_selector(&selector_and_hashes.selector,
|
||||
selector_list.0.iter().any(|selector| {
|
||||
matches_selector(selector,
|
||||
0,
|
||||
&selector_and_hashes.hashes,
|
||||
None,
|
||||
element,
|
||||
context,
|
||||
&mut |_, _| {})
|
||||
|
@ -371,7 +371,7 @@ enum SelectorMatchingResult {
|
|||
#[inline(always)]
|
||||
pub fn matches_selector<E, F>(selector: &Selector<E::Impl>,
|
||||
offset: usize,
|
||||
hashes: &AncestorHashes,
|
||||
hashes: Option<&AncestorHashes>,
|
||||
element: &E,
|
||||
context: &mut MatchingContext,
|
||||
flags_setter: &mut F)
|
||||
|
@ -380,9 +380,11 @@ pub fn matches_selector<E, F>(selector: &Selector<E::Impl>,
|
|||
F: FnMut(&E, ElementSelectorFlags),
|
||||
{
|
||||
// Use the bloom filter to fast-reject.
|
||||
if let Some(filter) = context.bloom_filter {
|
||||
if !may_match::<E>(hashes, filter) {
|
||||
return false;
|
||||
if let Some(hashes) = hashes {
|
||||
if let Some(filter) = context.bloom_filter {
|
||||
if !may_match::<E>(hashes, filter) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ impl<Impl: SelectorImpl> SelectorAndHashes<Impl> {
|
|||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub struct SelectorList<Impl: SelectorImpl>(pub Vec<SelectorAndHashes<Impl>>);
|
||||
pub struct SelectorList<Impl: SelectorImpl>(pub Vec<Selector<Impl>>);
|
||||
|
||||
impl<Impl: SelectorImpl> SelectorList<Impl> {
|
||||
/// Parse a comma-separated list of Selectors.
|
||||
|
@ -207,13 +207,13 @@ impl<Impl: SelectorImpl> SelectorList<Impl> {
|
|||
pub fn parse<'i, 't, P, E>(parser: &P, input: &mut CssParser<'i, 't>)
|
||||
-> Result<Self, ParseError<'i, SelectorParseError<'i, E>>>
|
||||
where P: Parser<'i, Impl=Impl, Error=E> {
|
||||
input.parse_comma_separated(|input| parse_selector(parser, input).map(SelectorAndHashes::new))
|
||||
input.parse_comma_separated(|input| parse_selector(parser, input))
|
||||
.map(SelectorList)
|
||||
}
|
||||
|
||||
/// Creates a SelectorList from a Vec of selectors. Used in tests.
|
||||
pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
|
||||
SelectorList(v.into_iter().map(SelectorAndHashes::new).collect())
|
||||
SelectorList(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -761,10 +761,10 @@ impl<Impl: SelectorImpl> ToCss for SelectorList<Impl> {
|
|||
let mut iter = self.0.iter();
|
||||
let first = iter.next()
|
||||
.expect("Empty SelectorList, should contain at least one selector");
|
||||
first.selector.to_css(dest)?;
|
||||
for selector_and_hashes in iter {
|
||||
first.to_css(dest)?;
|
||||
for selector in iter {
|
||||
dest.write_str(", ")?;
|
||||
selector_and_hashes.selector.to_css(dest)?;
|
||||
selector.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1761,7 +1761,7 @@ pub mod tests {
|
|||
let result = SelectorList::parse(parser, &mut CssParser::new(&mut parser_input));
|
||||
if let Ok(ref selectors) = result {
|
||||
assert_eq!(selectors.0.len(), 1);
|
||||
assert_eq!(selectors.0[0].selector.to_css_string(), input);
|
||||
assert_eq!(selectors.0[0].to_css_string(), input);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@ -2066,7 +2066,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_pseudo_iter() {
|
||||
let selector = &parse("q::before").unwrap().0[0].selector;
|
||||
let selector = &parse("q::before").unwrap().0[0];
|
||||
assert!(!selector.is_universal());
|
||||
let mut iter = selector.iter();
|
||||
assert_eq!(iter.next(), Some(&Component::PseudoElement(PseudoElement::Before)));
|
||||
|
@ -2080,13 +2080,13 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_universal() {
|
||||
let selector = &parse("*|*::before").unwrap().0[0].selector;
|
||||
let selector = &parse("*|*::before").unwrap().0[0];
|
||||
assert!(selector.is_universal());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_pseudo_iter() {
|
||||
let selector = &parse("::before").unwrap().0[0].selector;
|
||||
let selector = &parse("::before").unwrap().0[0];
|
||||
assert!(selector.is_universal());
|
||||
let mut iter = selector.iter();
|
||||
assert_eq!(iter.next(), Some(&Component::PseudoElement(PseudoElement::Before)));
|
||||
|
@ -2112,11 +2112,11 @@ pub mod tests {
|
|||
#[test]
|
||||
fn visitor() {
|
||||
let mut test_visitor = TestVisitor { seen: vec![], };
|
||||
parse(":not(:hover) ~ label").unwrap().0[0].selector.visit(&mut test_visitor);
|
||||
parse(":not(:hover) ~ label").unwrap().0[0].visit(&mut test_visitor);
|
||||
assert!(test_visitor.seen.contains(&":hover".into()));
|
||||
|
||||
let mut test_visitor = TestVisitor { seen: vec![], };
|
||||
parse("::before:hover").unwrap().0[0].selector.visit(&mut test_visitor);
|
||||
parse("::before:hover").unwrap().0[0].visit(&mut test_visitor);
|
||||
assert!(test_visitor.seen.contains(&":hover".into()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue