Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Dec 2, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

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

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.
  • Loading branch information
emilio committed Dec 1, 2017
commit 848a8581ac4fb16980d4cc6c990a91e3c61a60ed
@@ -213,27 +213,33 @@ impl Color {
// specified value.
let start = input.state();
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,
};
input.reset(&start);
match input.try(CSSParserColor::parse) {
Ok(value) =>
Ok(match value {
CSSParserColor::CurrentColor => Color::CurrentColor,
CSSParserColor::RGBA(rgba) => Color::Numeric {
parsed: rgba,
authored: authored,
},
CSSParserColor::RGBA(rgba) => {
Color::Numeric {
parsed: rgba,
authored: authored.map(|s| s.to_lowercase().into_boxed_str()),
}
}
}),
Err(e) => {
#[cfg(feature = "gecko")] {
#[cfg(feature = "gecko")]
{
if let Ok(system) = input.try(SystemColor::parse) {
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));
}
}

match e {
BasicParseError { kind: BasicParseErrorKind::UnexpectedToken(t), location } => {
Err(location.new_custom_error(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.