]> git.lizzy.rs Git - rust.git/commitdiff
string: Use the iterator size_hint() in .extend()
authorbluss <bluss>
Sun, 7 Dec 2014 20:31:24 +0000 (21:31 +0100)
committerbluss <bluss>
Sun, 7 Dec 2014 20:31:24 +0000 (21:31 +0100)
src/libcollections/string.rs

index fbb0bb5c4ce8673cf5fa71d3d34914a65d2ce024..961fca0f02b9a159dbdf9f2ee7c1297ecf364914 100644 (file)
@@ -732,6 +732,8 @@ fn from_iter<I:Iterator<char>>(iterator: I) -> String {
 #[experimental = "waiting on Extend stabilization"]
 impl Extend<char> for String {
     fn extend<I:Iterator<char>>(&mut self, mut iterator: I) {
+        let (lower_bound, _) = iterator.size_hint();
+        self.reserve(lower_bound);
         for ch in iterator {
             self.push(ch)
         }