Skip to content

Commit 7472886

Browse files
committed
Auto merge of #27986 - chris-morgan:reduce-string-extend-str-implementation, 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.
2 parents 5c630a6 + 81c1d14 commit 7472886

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/libcollections/string.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,7 @@ impl<'a> Extend<&'a char> for String {
813813
#[stable(feature = "rust1", since = "1.0.0")]
814814
impl<'a> Extend<&'a str> for String {
815815
fn extend<I: IntoIterator<Item=&'a str>>(&mut self, iterable: I) {
816-
let iterator = iterable.into_iter();
817-
// A guess that at least one byte per iterator element will be needed.
818-
let (lower_bound, _) = iterator.size_hint();
819-
self.reserve(lower_bound);
820-
for s in iterator {
816+
for s in iterable {
821817
self.push_str(s)
822818
}
823819
}

0 commit comments

Comments
 (0)