Skip to content

Commit

Permalink
Simplify String’s Extend<&str> implementation
Browse files Browse the repository at this point in the history
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
chris-morgan committed Aug 24, 2015
1 parent 4c99649 commit 81c1d14
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/libcollections/string.rs
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 81c1d14

Please sign in to comment.