Use Parser::skip_whitespace in a few places to make Parser::try rewind less.

Gecko’s CSS parsing microbenchmarks before:

```
  43.437 ±  0.391 ms    Stylo.Servo_StyleSheet_FromUTF8Bytes_Bench
  29.244 ±  0.042 ms    Stylo.Gecko_nsCSSParser_ParseSheet_Bench
 281.884 ±  0.028 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_Bench
 426.242 ±  0.008 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench
```

After:

```
  29.779 ±  0.254 ms    Stylo.Servo_StyleSheet_FromUTF8Bytes_Bench
  28.841 ±  0.031 ms    Stylo.Gecko_nsCSSParser_ParseSheet_Bench
 296.240 ±  4.744 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_Bench
 293.855 ±  4.304 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench
```
This commit is contained in:
Simon Sapin 2017-08-21 16:07:03 +02:00
parent 72c59ff830
commit dc5dfafbba
6 changed files with 44 additions and 44 deletions

View file

@ -1425,14 +1425,7 @@ fn parse_negation<'i, 't, P, E, Impl>(parser: &P,
// We use a sequence because a type selector may be represented as two Components.
let mut sequence = SmallVec::<[Component<Impl>; 2]>::new();
// Consume any leading whitespace.
loop {
let before_this_token = input.state();
if !matches!(input.next_including_whitespace(), Ok(&Token::WhiteSpace(_))) {
input.reset(&before_this_token);
break
}
}
input.skip_whitespace();
// Get exactly one simple selector. The parse logic in the caller will verify
// that there are no trailing tokens after we're done.
@ -1468,14 +1461,8 @@ fn parse_compound_selector<'i, 't, P, E, Impl>(
-> Result<bool, ParseError<'i, SelectorParseError<'i, E>>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl
{
// Consume any leading whitespace.
loop {
let before_this_token = input.state();
if !matches!(input.next_including_whitespace(), Ok(&Token::WhiteSpace(_))) {
input.reset(&before_this_token);
break
}
}
input.skip_whitespace();
let mut empty = true;
if !parse_type_selector(parser, input, builder)? {
if let Some(url) = parser.default_namespace() {