replace vector iteration by ascii_case_insensitive_phf_map

This commit is contained in:
Pavel Sergeev 2017-07-17 12:54:49 +03:00 committed by Pavel Sergeev
parent 17f99e2a7b
commit 6a2f84eca4

View file

@ -121,22 +121,21 @@
impl SystemColor {
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
#[cfg(feature = "gecko")]
use std::ascii::AsciiExt;
static PARSE_ARRAY: &'static [(&'static str, SystemColor); ${len(system_colors)}] = &[
ascii_case_insensitive_phf_map! {
color_name -> SystemColor = {
% for color in system_colors:
("${color}", LookAndFeel_ColorID::eColorID_${to_rust_ident(color)}),
"${color}" => LookAndFeel_ColorID::eColorID_${to_rust_ident(color)},
% endfor
];
}
}
let ident = input.expect_ident()?;
for &(name, color) in PARSE_ARRAY.iter() {
if name.eq_ignore_ascii_case(&ident) {
return Ok(color)
}
}
if let Some(color) = color_name(&ident) {
Ok(*color)
} else {
Err(SelectorParseError::UnexpectedIdent(ident).into())
}
}
}
% endif
</%helpers:longhand>