Auto merge of #17754 - SergeevPavel:system-colors-refactor, r=SimonSapin

replace vector iteration by ascii_case_insensitive_phf_map

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #15994 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/17754)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-07-19 14:56:24 -07:00 committed by GitHub
commit e7b195b060

View file

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