Skip to content

Commit b6110e5

Browse files
Convert consecutive String::push_str to String::extend
1 parent a87930f commit b6110e5

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ pub fn join_path_syms(path: impl IntoIterator<Item = impl Borrow<Symbol>>) -> St
181181
for sym in iter {
182182
let sym = *sym.borrow();
183183
debug_assert_ne!(sym, kw::PathRoot);
184-
s.push_str("::");
185-
s.push_str(sym.as_str());
184+
s.extend(["::", sym.as_str()]);
186185
}
187186
s
188187
}
@@ -201,8 +200,7 @@ pub fn join_path_idents(path: impl IntoIterator<Item = impl Borrow<Ident>>) -> S
201200
for ident in iter {
202201
let ident = *ident.borrow();
203202
debug_assert_ne!(ident.name, kw::PathRoot);
204-
s.push_str("::");
205-
s.push_str(&ident.to_string());
203+
s.extend(["::", &ident.to_string()]);
206204
}
207205
s
208206
}

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
334334
if self.paths.contains(&path_ident) {
335335
return;
336336
} else {
337-
self.fmt_string.push_str(" ");
338-
self.fmt_string.push_str(path_ident.as_str());
339-
self.fmt_string.push_str(" = {:?}\n");
337+
self.fmt_string.extend([" ", path_ident.as_str(), " = {:?}\n"]);
340338
let _ = self.paths.insert(path_ident);
341339
}
342340
let curr_capture_idx = self.capture_decls.len();

library/alloc/src/borrow.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use core::ops::{Deref, DerefPure};
1313
use Cow::*;
1414

1515
use crate::fmt;
16-
#[cfg(not(no_global_oom_handling))]
17-
use crate::string::String;
1816

1917
// FIXME(inference): const bounds removed due to inference regressions found by crater;
2018
// see https://github.com/rust-lang/rust/issues/147964
@@ -496,12 +494,14 @@ impl<'a> AddAssign<&'a str> for Cow<'a, str> {
496494
if self.is_empty() {
497495
*self = Cow::Borrowed(rhs)
498496
} else if !rhs.is_empty() {
499-
if let Cow::Borrowed(lhs) = *self {
500-
let mut s = String::with_capacity(lhs.len() + rhs.len());
501-
s.push_str(lhs);
502-
*self = Cow::Owned(s);
497+
match self {
498+
Self::Borrowed(lhs) => {
499+
*self = Cow::Owned([lhs, rhs].into_iter().collect());
500+
}
501+
Self::Owned(lhs) => {
502+
lhs.push_str(&rhs);
503+
}
503504
}
504-
self.to_mut().push_str(rhs);
505505
}
506506
}
507507
}
@@ -513,12 +513,14 @@ impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
513513
if self.is_empty() {
514514
*self = rhs
515515
} else if !rhs.is_empty() {
516-
if let Cow::Borrowed(lhs) = *self {
517-
let mut s = String::with_capacity(lhs.len() + rhs.len());
518-
s.push_str(lhs);
519-
*self = Cow::Owned(s);
516+
match self {
517+
Self::Borrowed(lhs) => {
518+
*self = Cow::Owned([&*lhs, &*rhs].into_iter().collect());
519+
}
520+
Self::Owned(lhs) => {
521+
lhs.push_str(&rhs);
522+
}
520523
}
521-
self.to_mut().push_str(&rhs);
522524
}
523525
}
524526
}

src/librustdoc/html/markdown.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,9 +1645,7 @@ pub(crate) fn plain_text_from_events<'a>(
16451645
match &event {
16461646
Event::Text(text) => s.push_str(text),
16471647
Event::Code(code) => {
1648-
s.push('`');
1649-
s.push_str(code);
1650-
s.push('`');
1648+
s.extend(["`", code, "`"]);
16511649
}
16521650
Event::HardBreak | Event::SoftBreak => s.push(' '),
16531651
Event::Start(Tag::CodeBlock(..)) => break,

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,8 +2257,7 @@ pub(crate) fn compare_names(left: &str, right: &str) -> Ordering {
22572257

22582258
pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String {
22592259
let mut s = join_path_syms(&cx.current);
2260-
s.push_str("::");
2261-
s.push_str(item.name.unwrap().as_str());
2260+
s.extend(["::", item.name.unwrap().as_str()]);
22622261
s
22632262
}
22642263

0 commit comments

Comments
 (0)