servo: Merge #17754 - replace vector iteration by ascii_case_insensitive_phf_map (from SergeevPavel:system-colors-refactor); r=SimonSapin
authorPavel Sergeev <sergeev.pavel.al@gmail.com>
Wed, 19 Jul 2017 14:56:24 -0700
changeset 418468 986de13adb0a2b7ba6369deaccdd583915857d91
parent 418467 4a7dd87506167cf613c905f0249cceb70c7a6b7c
child 418469 7eb11c4b0159a321d2f4b06b57336c507daea216
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
bugs17754, 15994
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17754 - replace vector iteration by ascii_case_insensitive_phf_map (from SergeevPavel:system-colors-refactor); r=SimonSapin <!-- 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. --> Source-Repo: https://github.com/servo/servo Source-Revision: e7b195b060fc9240393ad2754d3a92829b406541
servo/components/style/properties/longhand/color.mako.rs
--- a/servo/components/style/properties/longhand/color.mako.rs
+++ b/servo/components/style/properties/longhand/color.mako.rs
@@ -116,27 +116,26 @@
             #[inline]
             fn from_computed_value(_: &Self::ComputedValue) -> Self {
                 unreachable!()
             }
         }
 
         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)}] = &[
-                    % for color in system_colors:
-                        ("${color}", LookAndFeel_ColorID::eColorID_${to_rust_ident(color)}),
-                    % endfor
-                ];
+                ascii_case_insensitive_phf_map! {
+                    color_name -> SystemColor = {
+                        % for color in system_colors:
+                            "${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())
                 }
-                Err(SelectorParseError::UnexpectedIdent(ident).into())
             }
         }
     % endif
 </%helpers:longhand>