style: Make weird color parsing marginally faster.

This commit is contained in:
Emilio Cobos Álvarez 2018-03-08 14:08:54 +01:00
parent 2192090ea5
commit 0717047e1e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 8 additions and 8 deletions

View file

@ -63,7 +63,6 @@ pub mod system_colors {
IMESelectedConvertedTextBackground IMESelectedConvertedTextForeground IMESelectedConvertedTextBackground IMESelectedConvertedTextForeground
IMESelectedConvertedTextUnderline SpellCheckerUnderline""".split() IMESelectedConvertedTextUnderline SpellCheckerUnderline""".split()
%> %>
use cssparser::Parser;
use gecko_bindings::bindings::Gecko_GetLookAndFeelSystemColor; use gecko_bindings::bindings::Gecko_GetLookAndFeelSystemColor;
use gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID; use gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
@ -109,7 +108,7 @@ pub mod system_colors {
} }
impl SystemColor { impl SystemColor {
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>,) -> Result<Self, ()> { pub fn from_ident<'i, 't>(ident: &str) -> Result<Self, ()> {
ascii_case_insensitive_phf_map! { ascii_case_insensitive_phf_map! {
color_name -> SystemColor = { color_name -> SystemColor = {
% for color in system_colors: % for color in system_colors:
@ -118,7 +117,6 @@ pub mod system_colors {
} }
} }
let ident = input.expect_ident().map_err(|_| ())?;
color_name(ident).cloned().ok_or(()) color_name(ident).cloned().ok_or(())
} }
} }

View file

@ -160,14 +160,16 @@ impl Parse for Color {
Err(e) => { Err(e) => {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if let Ok(system) = input.try(SystemColor::parse) { if let Ok(ident) = input.expect_ident() {
if let Ok(system) = SystemColor::from_ident(ident) {
return Ok(Color::System(system)); return Ok(Color::System(system));
} }
if let Ok(c) = gecko::SpecialColorKeyword::parse(input) { if let Ok(c) = gecko::SpecialColorKeyword::from_ident(ident) {
return Ok(Color::Special(c)); return Ok(Color::Special(c));
} }
} }
}
match e.kind { match e.kind {
ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(t)) => { ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(t)) => {