mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
72c59ff830
commit
dc5dfafbba
6 changed files with 44 additions and 44 deletions
|
@ -246,11 +246,16 @@ impl Separator for Space {
|
|||
where
|
||||
F: for<'tt> FnMut(&mut Parser<'i, 'tt>) -> Result<T, ParseError<'i, E>>
|
||||
{
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
let mut results = vec![parse_one(input)?];
|
||||
while let Ok(item) = input.try(&mut parse_one) {
|
||||
results.push(item);
|
||||
loop {
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
if let Ok(item) = input.try(&mut parse_one) {
|
||||
results.push(item);
|
||||
} else {
|
||||
return Ok(results)
|
||||
}
|
||||
}
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,9 +271,12 @@ impl Separator for CommaWithSpace {
|
|||
where
|
||||
F: for<'tt> FnMut(&mut Parser<'i, 'tt>) -> Result<T, ParseError<'i, E>>
|
||||
{
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
let mut results = vec![parse_one(input)?];
|
||||
loop {
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
let comma = input.try(|i| i.expect_comma()).is_ok();
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
if let Ok(item) = input.try(&mut parse_one) {
|
||||
results.push(item);
|
||||
} else if comma {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue