Skip to content

Commit fcb3ce4

Browse files
authored
Rollup merge of rust-lang#54932 - ljedrz:a_handful_of_string_improvements, r=alexcrichton
A handful of random string-related improvements - remove a few allocations in `errors/diagnostic` - make `build_helper::gnu_target` return `Cow<str>`
2 parents b39535d + a01a994 commit fcb3ce4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/build_helper/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ pub fn try_run_suppressed(cmd: &mut Command) -> bool {
9191
output.status.success()
9292
}
9393

94-
pub fn gnu_target(target: &str) -> String {
94+
pub fn gnu_target(target: &str) -> &str {
9595
match target {
96-
"i686-pc-windows-msvc" => "i686-pc-win32".to_string(),
97-
"x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(),
98-
"i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(),
99-
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(),
100-
s => s.to_string(),
96+
"i686-pc-windows-msvc" => "i686-pc-win32",
97+
"x86_64-pc-windows-msvc" => "x86_64-pc-win32",
98+
"i686-pc-windows-gnu" => "i686-w64-mingw32",
99+
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32",
100+
s => s,
101101
}
102102
}
103103

src/librustc_errors/diagnostic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ pub enum StringPart {
7676
}
7777

7878
impl StringPart {
79-
pub fn content(&self) -> String {
79+
pub fn content(&self) -> &str {
8080
match self {
81-
&StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s.to_owned()
81+
&StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s
8282
}
8383
}
8484
}
@@ -398,7 +398,7 @@ impl Diagnostic {
398398
}
399399

400400
pub fn message(&self) -> String {
401-
self.message.iter().map(|i| i.0.to_owned()).collect::<String>()
401+
self.message.iter().map(|i| i.0.as_str()).collect::<String>()
402402
}
403403

404404
pub fn styled_message(&self) -> &Vec<(String, Style)> {
@@ -448,7 +448,7 @@ impl Diagnostic {
448448

449449
impl SubDiagnostic {
450450
pub fn message(&self) -> String {
451-
self.message.iter().map(|i| i.0.to_owned()).collect::<String>()
451+
self.message.iter().map(|i| i.0.as_str()).collect::<String>()
452452
}
453453

454454
pub fn styled_message(&self) -> &Vec<(String, Style)> {

0 commit comments

Comments
 (0)