Commit e9e92d5
authored
Rollup merge of rust-lang#56548 - Lucretiel:string-extend-optimize, r=sfackler
Optimized string FromIterator + Extend impls
I noticed that there was a lost opportunity to reuse string buffers in `FromIterator<String>` and `FromIterator<Cow<str>>`; updated the implementations to use these. In practice this translates to at least one fewer allocation when using these APIs.
Additionally, rewrote `Extend` implementations to use `iter.for_each`, which (supposedly) helps the compiler optimize those loops (because iterator adapters are encouraged to provide optimized implementations of `fold` and `try_fold`.1 file changed
+29
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1732 | 1732 | | |
1733 | 1733 | | |
1734 | 1734 | | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1738 | 1747 | | |
1739 | 1748 | | |
1740 | 1749 | | |
1741 | 1750 | | |
1742 | 1751 | | |
1743 | 1752 | | |
1744 | | - | |
1745 | | - | |
1746 | | - | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
1747 | 1766 | | |
1748 | 1767 | | |
1749 | 1768 | | |
| |||
1753 | 1772 | | |
1754 | 1773 | | |
1755 | 1774 | | |
1756 | | - | |
1757 | | - | |
1758 | | - | |
| 1775 | + | |
1759 | 1776 | | |
1760 | 1777 | | |
1761 | 1778 | | |
| |||
1769 | 1786 | | |
1770 | 1787 | | |
1771 | 1788 | | |
1772 | | - | |
1773 | | - | |
1774 | | - | |
| 1789 | + | |
1775 | 1790 | | |
1776 | 1791 | | |
1777 | 1792 | | |
1778 | 1793 | | |
1779 | 1794 | | |
1780 | 1795 | | |
1781 | | - | |
1782 | | - | |
1783 | | - | |
| 1796 | + | |
1784 | 1797 | | |
1785 | 1798 | | |
1786 | 1799 | | |
1787 | 1800 | | |
1788 | 1801 | | |
1789 | 1802 | | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
| 1803 | + | |
1793 | 1804 | | |
1794 | 1805 | | |
1795 | 1806 | | |
| |||
0 commit comments