Auto merge of #19455 - emilio:color-does-stupid-things-too, r=upsuper

style: Don't waste an allocation when failing to parse a CSSParserColor.

I see that allocation show up in the profiles, and it makes sense, because
system colors and such are common in Firefox, and they're just wasting it.

Note that the clone() added is refcounted.

<!-- 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/19455)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-12-01 18:03:11 -06:00 committed by GitHub
commit 49e6594bc9

View file

@ -213,7 +213,7 @@ impl Color {
// specified value. // specified value.
let start = input.state(); let start = input.state();
let authored = match input.next() { let authored = match input.next() {
Ok(&Token::Ident(ref s)) => Some(s.to_lowercase().into_boxed_str()), Ok(&Token::Ident(ref s)) => Some(s.clone()),
_ => None, _ => None,
}; };
input.reset(&start); input.reset(&start);
@ -221,19 +221,25 @@ impl Color {
Ok(value) => Ok(value) =>
Ok(match value { Ok(match value {
CSSParserColor::CurrentColor => Color::CurrentColor, CSSParserColor::CurrentColor => Color::CurrentColor,
CSSParserColor::RGBA(rgba) => Color::Numeric { CSSParserColor::RGBA(rgba) => {
Color::Numeric {
parsed: rgba, parsed: rgba,
authored: authored, authored: authored.map(|s| s.to_lowercase().into_boxed_str()),
}, }
}
}), }),
Err(e) => { Err(e) => {
#[cfg(feature = "gecko")] { #[cfg(feature = "gecko")]
{
if let Ok(system) = input.try(SystemColor::parse) { if let Ok(system) = input.try(SystemColor::parse) {
return Ok(Color::System(system)); return Ok(Color::System(system));
} else if let Ok(c) = gecko::SpecialColorKeyword::parse(input) { }
if let Ok(c) = gecko::SpecialColorKeyword::parse(input) {
return Ok(Color::Special(c)); return Ok(Color::Special(c));
} }
} }
match e { match e {
BasicParseError { kind: BasicParseErrorKind::UnexpectedToken(t), location } => { BasicParseError { kind: BasicParseErrorKind::UnexpectedToken(t), location } => {
Err(location.new_custom_error( Err(location.new_custom_error(