Auto merge of #16141 - emilio:keyword-from-ident, r=nox

style: Add <keyword>::from_ident helper to avoid tokenizing the same value multiple times.

We can use this to avoid tokenizing multiple times in some places, like #16127.

<!-- 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/16141)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-26 17:21:49 -07:00 committed by GitHub
commit 447742b0a7

View file

@ -117,7 +117,12 @@ macro_rules! __define_css_keyword_enum__actual {
/// Parse this property from a CSS input stream.
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
let ident = input.expect_ident()?;
match_ignore_ascii_case! { &ident,
Self::from_ident(&ident)
}
/// Parse this property from an already-tokenized identifier.
pub fn from_ident(ident: &str) -> Result<$name, ()> {
match_ignore_ascii_case! { ident,
$( $css => Ok($name::$variant), )+
_ => Err(())
}