mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use ascii_case_insensitive_phf_map in TransitionProperty::parse
This divides the size of this method by 30.
This commit is contained in:
parent
c92d0a8902
commit
e2c674994a
1 changed files with 33 additions and 13 deletions
|
@ -24,7 +24,6 @@ use properties::longhands::visibility::computed_value::T as Visibility;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use properties::PropertyId;
|
use properties::PropertyId;
|
||||||
use properties::{LonghandId, ShorthandId};
|
use properties::{LonghandId, ShorthandId};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{cmp, ptr};
|
use std::{cmp, ptr};
|
||||||
|
@ -142,21 +141,42 @@ impl TransitionProperty {
|
||||||
|
|
||||||
/// Parse a transition-property value.
|
/// Parse a transition-property value.
|
||||||
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
// FIXME(https://github.com/rust-lang/rust/issues/33156): remove this
|
||||||
let ident = input.expect_ident()?;
|
// enum and use PropertyId when stable Rust allows destructors in
|
||||||
match_ignore_ascii_case! { &ident,
|
// statics.
|
||||||
"all" => Ok(TransitionProperty::All),
|
//
|
||||||
|
// FIXME: This should handle aliases too.
|
||||||
|
pub enum StaticId {
|
||||||
|
All,
|
||||||
|
Longhand(LonghandId),
|
||||||
|
Shorthand(ShorthandId),
|
||||||
|
}
|
||||||
|
ascii_case_insensitive_phf_map! {
|
||||||
|
static_id -> StaticId = {
|
||||||
|
"all" => StaticId::All,
|
||||||
% for prop in data.shorthands_except_all():
|
% for prop in data.shorthands_except_all():
|
||||||
"${prop.name}" => Ok(TransitionProperty::Shorthand(ShorthandId::${prop.camel_case})),
|
"${prop.name}" => StaticId::Shorthand(ShorthandId::${prop.camel_case}),
|
||||||
% endfor
|
% endfor
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
"${prop.name}" => Ok(TransitionProperty::Longhand(LonghandId::${prop.camel_case})),
|
"${prop.name}" => StaticId::Longhand(LonghandId::${prop.camel_case}),
|
||||||
% endfor
|
% endfor
|
||||||
"none" => Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))),
|
|
||||||
_ => CustomIdent::from_ident(location, ident, &[]).map(TransitionProperty::Unsupported),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let location = input.current_source_location();
|
||||||
|
let ident = input.expect_ident()?;
|
||||||
|
|
||||||
|
Ok(match static_id(&ident) {
|
||||||
|
Some(&StaticId::All) => TransitionProperty::All,
|
||||||
|
Some(&StaticId::Longhand(id)) => TransitionProperty::Longhand(id),
|
||||||
|
Some(&StaticId::Shorthand(id)) => TransitionProperty::Shorthand(id),
|
||||||
|
None => {
|
||||||
|
TransitionProperty::Unsupported(
|
||||||
|
CustomIdent::from_ident(location, ident, &["none"])?,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert TransitionProperty to nsCSSPropertyID.
|
/// Convert TransitionProperty to nsCSSPropertyID.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue