mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Auto merge of #20185 - Beta-Alf:master, r=emilio
Make KeyframesPercentage::parse faster Minor refactoring of the parsing of keyframes. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #20179 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because it is a minor refactor so tests are already in place. The original Issue explicitly says so. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20185) <!-- Reviewable:end -->
This commit is contained in:
commit
29e10d4f88
1 changed files with 16 additions and 15 deletions
|
@ -5,7 +5,7 @@
|
|||
//! Keyframes: https://drafts.csswg.org/css-animations/#keyframes
|
||||
|
||||
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, ParserInput, CowRcStr};
|
||||
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation};
|
||||
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation, Token};
|
||||
use error_reporting::{NullReporter, ContextualParseError, ParseErrorReporter};
|
||||
use parser::{ParserContext, ParserErrorContext};
|
||||
use properties::{DeclarationSource, Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
||||
|
@ -126,20 +126,21 @@ impl KeyframePercentage {
|
|||
}
|
||||
|
||||
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<KeyframePercentage, ParseError<'i>> {
|
||||
let percentage = if input.try(|input| input.expect_ident_matching("from")).is_ok() {
|
||||
KeyframePercentage::new(0.)
|
||||
} else if input.try(|input| input.expect_ident_matching("to")).is_ok() {
|
||||
KeyframePercentage::new(1.)
|
||||
} else {
|
||||
let percentage = input.expect_percentage()?;
|
||||
if percentage >= 0. && percentage <= 1. {
|
||||
KeyframePercentage::new(percentage)
|
||||
} else {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(percentage)
|
||||
let token = input.next()?.clone();
|
||||
match token {
|
||||
Token::Ident(ref identifier) if identifier.as_ref().eq_ignore_ascii_case("from") => {
|
||||
Ok(KeyframePercentage::new(0.))
|
||||
},
|
||||
Token::Ident(ref identifier) if identifier.as_ref().eq_ignore_ascii_case("to") => {
|
||||
Ok(KeyframePercentage::new(1.))
|
||||
},
|
||||
Token::Percentage { unit_value: percentage, .. } if percentage >= 0. && percentage <= 1. => {
|
||||
Ok(KeyframePercentage::new(percentage))
|
||||
},
|
||||
_ => {
|
||||
Err(input.new_unexpected_token_error(token))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue