From 81c1d142d31736a8b65c111c3aa4a1a5723ee4e5 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 25 Aug 2015 07:47:42 +1000 Subject: [PATCH] =?UTF-8?q?Simplify=20`String`=E2=80=99s=20`Extend<&str>`?= =?UTF-8?q?=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/libcollections/string.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 5c5f6cace6a..a8f030c437d 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -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>(&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) } }