mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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.
This commit is contained in:
parent
712d75af01
commit
848a8581ac
1 changed files with 13 additions and 7 deletions
|
@ -213,7 +213,7 @@ 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);
|
||||
|
@ -221,19 +221,25 @@ impl Color {
|
|||
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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue