mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Use a 1-element smallvec for selector lists.
This commit is contained in:
parent
00867711b3
commit
3ae7781b5f
1 changed files with 12 additions and 5 deletions
|
@ -7,7 +7,7 @@ use attr::{ParsedCaseSensitivity, SELECTOR_WHITESPACE, NamespaceConstraint};
|
||||||
use bloom::BLOOM_HASH_MASK;
|
use bloom::BLOOM_HASH_MASK;
|
||||||
use builder::{SelectorBuilder, SpecificityAndFlags};
|
use builder::{SelectorBuilder, SpecificityAndFlags};
|
||||||
use context::QuirksMode;
|
use context::QuirksMode;
|
||||||
use cssparser::{ParseError, BasicParseError, CowRcStr};
|
use cssparser::{ParseError, BasicParseError, CowRcStr, Delimiter};
|
||||||
use cssparser::{Token, Parser as CssParser, parse_nth, ToCss, serialize_identifier, CssStringWriter};
|
use cssparser::{Token, Parser as CssParser, parse_nth, ToCss, serialize_identifier, CssStringWriter};
|
||||||
use precomputed_hash::PrecomputedHash;
|
use precomputed_hash::PrecomputedHash;
|
||||||
use servo_arc::ThinArc;
|
use servo_arc::ThinArc;
|
||||||
|
@ -176,7 +176,7 @@ pub trait Parser<'i> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct SelectorList<Impl: SelectorImpl>(pub Vec<Selector<Impl>>);
|
pub struct SelectorList<Impl: SelectorImpl>(pub SmallVec<[Selector<Impl>; 1]>);
|
||||||
|
|
||||||
impl<Impl: SelectorImpl> SelectorList<Impl> {
|
impl<Impl: SelectorImpl> SelectorList<Impl> {
|
||||||
/// Parse a comma-separated list of Selectors.
|
/// Parse a comma-separated list of Selectors.
|
||||||
|
@ -186,13 +186,20 @@ impl<Impl: SelectorImpl> SelectorList<Impl> {
|
||||||
pub fn parse<'i, 't, P, E>(parser: &P, input: &mut CssParser<'i, 't>)
|
pub fn parse<'i, 't, P, E>(parser: &P, input: &mut CssParser<'i, 't>)
|
||||||
-> Result<Self, ParseError<'i, SelectorParseError<'i, E>>>
|
-> Result<Self, ParseError<'i, SelectorParseError<'i, E>>>
|
||||||
where P: Parser<'i, Impl=Impl, Error=E> {
|
where P: Parser<'i, Impl=Impl, Error=E> {
|
||||||
input.parse_comma_separated(|input| parse_selector(parser, input))
|
let mut values = SmallVec::new();
|
||||||
.map(SelectorList)
|
loop {
|
||||||
|
values.push(input.parse_until_before(Delimiter::Comma, |input| parse_selector(parser, input))?);
|
||||||
|
match input.next() {
|
||||||
|
Err(_) => return Ok(SelectorList(values)),
|
||||||
|
Ok(&Token::Comma) => continue,
|
||||||
|
Ok(_) => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a SelectorList from a Vec of selectors. Used in tests.
|
/// Creates a SelectorList from a Vec of selectors. Used in tests.
|
||||||
pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
|
pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
|
||||||
SelectorList(v)
|
SelectorList(SmallVec::from_vec(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue