diff options
| author | Nathan West <Lucretiel@users.noreply.github.com> | 2018-12-05 17:46:03 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-05 17:46:03 -0800 |
| commit | 811a2bfe5332081d7145de6c488ea7f6c5cf42a5 (patch) | |
| tree | d3be0a038ec73b7e7cadf5efbe006a006c5d94bd /src/liballoc | |
| parent | 823dd8ca334951962e8b192ca1362c08e33d6bcf (diff) | |
| download | rust-811a2bfe5332081d7145de6c488ea7f6c5cf42a5.tar.gz rust-811a2bfe5332081d7145de6c488ea7f6c5cf42a5.zip | |
Added explainatory comments
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/string.rs | 6 |
1 files changed, 6 insertions, 0 deletions
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<String> for String { fn from_iter<I: IntoIterator<Item = String>>(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<Cow<'a, str>> for String { fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(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) => { |
