diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-08-18 05:46:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-18 05:46:48 -0500 |
commit | b8159e659e787c1e792d13b0939bb88e978ae84e (patch) | |
tree | c3b60ab71992abf5edb850379ef5a1a63cb96f43 | |
parent | 92176d1152257e57e81dcd9204d59348ce9ff519 (diff) | |
parent | 86f162892879bd763b48be64084af99735594872 (diff) | |
download | servo-b8159e659e787c1e792d13b0939bb88e978ae84e.tar.gz servo-b8159e659e787c1e792d13b0939bb88e978ae84e.zip |
Auto merge of #18135 - jdm:lesstring, r=emilio
Use fewer allocations when reporting Gecko errors.
Avoid some unnecessary string allocations when extracting meaningful values out of CSS parser error messages.
---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] There are tests for these changes
<!-- 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/18135)
<!-- Reviewable:end -->
-rw-r--r-- | ports/geckolib/error_reporter.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/ports/geckolib/error_reporter.rs b/ports/geckolib/error_reporter.rs index c82cc9c0fe4..28d7648d2f0 100644 --- a/ports/geckolib/error_reporter.rs +++ b/ports/geckolib/error_reporter.rs @@ -50,11 +50,11 @@ enum ErrorString<'a> { } impl<'a> ErrorString<'a> { - fn into_str(self) -> String { + fn into_str(self) -> CowRcStr<'a> { match self { - ErrorString::Snippet(s) => s.as_ref().to_owned(), - ErrorString::Ident(i) => escape_css_ident(&i), - ErrorString::UnexpectedToken(t) => token_to_str(t), + ErrorString::Snippet(s) => s, + ErrorString::Ident(i) => escape_css_ident(&i).into(), + ErrorString::UnexpectedToken(t) => token_to_str(t).into(), } } } @@ -158,9 +158,9 @@ fn token_to_str<'a>(t: Token<'a>) -> String { Token::Percentage { int_value: Some(i), .. } => i.to_string(), Token::Percentage { unit_value, .. } => unit_value.to_string(), Token::Dimension { int_value: Some(i), ref unit, .. } => - format!("{}{}", i.to_string(), escape_css_ident(&unit.to_string())), + format!("{}{}", i, escape_css_ident(&*unit)), Token::Dimension { value, ref unit, .. } => - format!("{}{}", value.to_string(), escape_css_ident(&unit.to_string())), + format!("{}{}", value, escape_css_ident(&*unit)), Token::WhiteSpace(_) => "whitespace".into(), Token::Comment(_) => "comment".into(), Token::Colon => ":".into(), |