mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -37,7 +37,7 @@ bitflags = "0.7"
|
|||
bit-vec = "0.4.3"
|
||||
byteorder = "1.0"
|
||||
cfg-if = "0.1.0"
|
||||
cssparser = "0.19"
|
||||
cssparser = "0.19.3"
|
||||
encoding = {version = "0.2", optional = true}
|
||||
euclid = "0.15"
|
||||
fnv = "1.0"
|
||||
|
|
|
@ -1547,8 +1547,12 @@ impl PropertyDeclaration {
|
|||
id: PropertyId, context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<(), PropertyDeclarationParseError<'i>> {
|
||||
assert!(declarations.is_empty());
|
||||
let start = input.state();
|
||||
match id {
|
||||
PropertyId::Custom(name) => {
|
||||
// FIXME: fully implement https://github.com/w3c/csswg-drafts/issues/774
|
||||
// before adding skip_whitespace here.
|
||||
// This probably affects some test results.
|
||||
let value = match input.try(|i| CSSWideKeyword::parse(i)) {
|
||||
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword),
|
||||
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
||||
|
@ -1561,11 +1565,11 @@ impl PropertyDeclaration {
|
|||
Ok(())
|
||||
}
|
||||
PropertyId::Longhand(id) => {
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
input.try(|i| CSSWideKeyword::parse(i)).map(|keyword| {
|
||||
PropertyDeclaration::CSSWideKeyword(id, keyword)
|
||||
}).or_else(|()| {
|
||||
input.look_for_var_functions();
|
||||
let start = input.state();
|
||||
input.parse_entirely(|input| id.parse_value(context, input))
|
||||
.or_else(|err| {
|
||||
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||
|
@ -1592,6 +1596,7 @@ impl PropertyDeclaration {
|
|||
})
|
||||
}
|
||||
PropertyId::Shorthand(id) => {
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(i)) {
|
||||
if id == ShorthandId::All {
|
||||
declarations.all_shorthand = AllShorthand::CSSWideKeyword(keyword)
|
||||
|
@ -1603,7 +1608,6 @@ impl PropertyDeclaration {
|
|||
Ok(())
|
||||
} else {
|
||||
input.look_for_var_functions();
|
||||
let start = input.state();
|
||||
// Not using parse_entirely here: each ${shorthand.ident}::parse_into function
|
||||
// needs to do so *before* pushing to `declarations`.
|
||||
id.parse_into(declarations, context, input).or_else(|err| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue