From 811a2bfe5332081d7145de6c488ea7f6c5cf42a5 Mon Sep 17 00:00:00 2001 From: Nathan West Date: Wed, 5 Dec 2018 17:46:03 -0800 Subject: Added explainatory comments --- src/liballoc/string.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 6962f2ba852..f0a64f4631a 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1734,6 +1734,9 @@ impl FromIterator for String { fn from_iter>(iter: I) -> String { let mut iterator = iter.into_iter(); + // Because we're iterating over `String`s, we can avoid at least + // one allocation by getting the first string from the iterator + // and appending to it all the subsequent strings. match iterator.next() { None => String::new(), Some(mut buf) => { @@ -1749,6 +1752,9 @@ impl<'a> FromIterator> for String { fn from_iter>>(iter: I) -> String { let mut iterator = iter.into_iter(); + // Because we're iterating over CoWs, we can (potentially) avoid at least + // one allocation by getting the first item and appending to it all the + // subsequent items. match iterator.next() { None => String::new(), Some(cow) => { -- cgit 1.4.1-3-g733a5