Skip to content

Commit

Permalink
Auto merge of #27986 - chris-morgan:reduce-string-extend-str-implemen…
Browse files Browse the repository at this point in the history
…tation, r=bluss

Reserving lower_bound bytes was just silly. It’d be perfectly reasonable
to have empty strings in the iterator, which could cause superfluous
reallocation of the string, or to have more than one byte per string,
which could cause additional reallocation (in practice it’ll balance
out). The added complexity of this logic is simply pointless, adding
a little bloat with no demonstrable advantage and slight disadvantage.
  • Loading branch information
bors committed Aug 25, 2015
2 parents 5c630a6 + 81c1d14 commit 7472886
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,7 @@ impl<'a> Extend<&'a char> for String {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Extend<&'a str> for String {
fn extend<I: IntoIterator<Item=&'a str>>(&mut self, iterable: I) {
let iterator = iterable.into_iter();
// A guess that at least one byte per iterator element will be needed.
let (lower_bound, _) = iterator.size_hint();
self.reserve(lower_bound);
for s in iterator {
for s in iterable {
self.push_str(s)
}
}
Expand Down

0 comments on commit 7472886

Please # to comment.