File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -1734,6 +1734,9 @@ impl FromIterator<String> for String {
1734
1734
fn from_iter < I : IntoIterator < Item = String > > ( iter : I ) -> String {
1735
1735
let mut iterator = iter. into_iter ( ) ;
1736
1736
1737
+ // Because we're iterating over `String`s, we can avoid at least
1738
+ // one allocation by getting the first string from the iterator
1739
+ // and appending to it all the subsequent strings.
1737
1740
match iterator. next ( ) {
1738
1741
None => String :: new ( ) ,
1739
1742
Some ( mut buf) => {
@@ -1749,6 +1752,9 @@ impl<'a> FromIterator<Cow<'a, str>> for String {
1749
1752
fn from_iter < I : IntoIterator < Item = Cow < ' a , str > > > ( iter : I ) -> String {
1750
1753
let mut iterator = iter. into_iter ( ) ;
1751
1754
1755
+ // Because we're iterating over CoWs, we can (potentially) avoid at least
1756
+ // one allocation by getting the first item and appending to it all the
1757
+ // subsequent items.
1752
1758
match iterator. next ( ) {
1753
1759
None => String :: new ( ) ,
1754
1760
Some ( cow) => {
You can’t perform that action at this time.
0 commit comments