Commit ca38434
committed
auto merge of #15638 : blake2-ppc/rust/ptr-arithmetic-chars, r=huonw
Reimplement the string slice's `Iterator<char>` by wrapping the already efficient
slice iterator.
The iterator uses our guarantee that the string contains valid UTF-8, but its only unsafe
code is transmuting the decoded `u32` into `char`.
Benchmarks suggest that the runtime of `Chars` benchmarks are reduced by up to 30%,
runtime of `Chars` reversed reduced by up to 60%.
```
BEFORE
test str::bench::char_indicesator ... bench: 124 ns/iter (+/- 1)
test str::bench::char_indicesator_rev ... bench: 188 ns/iter (+/- 9)
test str::bench::char_iterator ... bench: 122 ns/iter (+/- 2)
test str::bench::char_iterator_ascii ... bench: 302 ns/iter (+/- 41)
test str::bench::char_iterator_for ... bench: 123 ns/iter (+/- 4)
test str::bench::char_iterator_rev ... bench: 189 ns/iter (+/- 14)
test str::bench::char_iterator_rev_for ... bench: 177 ns/iter (+/- 4)
AFTER
test str::bench::char_indicesator ... bench: 85 ns/iter (+/- 3)
test str::bench::char_indicesator_rev ... bench: 82 ns/iter (+/- 2)
test str::bench::char_iterator ... bench: 100 ns/iter (+/- 3)
test str::bench::char_iterator_ascii ... bench: 317 ns/iter (+/- 3)
test str::bench::char_iterator_for ... bench: 86 ns/iter (+/- 2)
test str::bench::char_iterator_rev ... bench: 80 ns/iter (+/- 6)
test str::bench::char_iterator_rev_for ... bench: 68 ns/iter (+/- 0)
```
Note: Branch name is no longer indicative of the implementation.2 files changed
+161
-57
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
808 | 808 | | |
809 | 809 | | |
810 | 810 | | |
| 811 | + | |
811 | 812 | | |
812 | 813 | | |
813 | 814 | | |
| |||
1610 | 1611 | | |
1611 | 1612 | | |
1612 | 1613 | | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
1613 | 1638 | | |
1614 | 1639 | | |
1615 | 1640 | | |
| |||
2240 | 2265 | | |
2241 | 2266 | | |
2242 | 2267 | | |
| 2268 | + | |
2243 | 2269 | | |
| 2270 | + | |
2244 | 2271 | | |
2245 | 2272 | | |
2246 | 2273 | | |
2247 | 2274 | | |
2248 | 2275 | | |
2249 | 2276 | | |
2250 | | - | |
2251 | 2277 | | |
2252 | | - | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
2253 | 2288 | | |
2254 | 2289 | | |
2255 | 2290 | | |
| |||
2260 | 2295 | | |
2261 | 2296 | | |
2262 | 2297 | | |
2263 | | - | |
2264 | 2298 | | |
2265 | | - | |
| 2299 | + | |
2266 | 2300 | | |
2267 | 2301 | | |
2268 | 2302 | | |
2269 | 2303 | | |
2270 | 2304 | | |
2271 | | - | |
2272 | 2305 | | |
2273 | | - | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
2274 | 2316 | | |
2275 | 2317 | | |
2276 | 2318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | | - | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
106 | 130 | | |
107 | 131 | | |
108 | 132 | | |
109 | 133 | | |
110 | 134 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
117 | 159 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
121 | 165 | | |
122 | 166 | | |
123 | 167 | | |
124 | 168 | | |
125 | 169 | | |
126 | | - | |
| 170 | + | |
| 171 | + | |
127 | 172 | | |
128 | 173 | | |
129 | 174 | | |
130 | 175 | | |
131 | 176 | | |
132 | 177 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
137 | 196 | | |
138 | | - | |
139 | | - | |
140 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
141 | 204 | | |
142 | 205 | | |
143 | 206 | | |
| |||
146 | 209 | | |
147 | 210 | | |
148 | 211 | | |
149 | | - | |
150 | | - | |
| 212 | + | |
151 | 213 | | |
152 | 214 | | |
153 | 215 | | |
154 | 216 | | |
155 | 217 | | |
156 | 218 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
161 | 229 | | |
162 | 230 | | |
163 | 231 | | |
| |||
169 | 237 | | |
170 | 238 | | |
171 | 239 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
177 | 248 | | |
178 | 249 | | |
179 | 250 | | |
| |||
672 | 743 | | |
673 | 744 | | |
674 | 745 | | |
675 | | - | |
| 746 | + | |
676 | 747 | | |
677 | | - | |
| 748 | + | |
678 | 749 | | |
679 | 750 | | |
680 | 751 | | |
| |||
683 | 754 | | |
684 | 755 | | |
685 | 756 | | |
686 | | - | |
| 757 | + | |
687 | 758 | | |
688 | 759 | | |
689 | 760 | | |
| |||
880 | 951 | | |
881 | 952 | | |
882 | 953 | | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
896 | 958 | | |
897 | 959 | | |
898 | 960 | | |
| |||
1608 | 1670 | | |
1609 | 1671 | | |
1610 | 1672 | | |
1611 | | - | |
| 1673 | + | |
1612 | 1674 | | |
1613 | 1675 | | |
1614 | 1676 | | |
| |||
1618 | 1680 | | |
1619 | 1681 | | |
1620 | 1682 | | |
1621 | | - | |
| 1683 | + | |
1622 | 1684 | | |
1623 | 1685 | | |
1624 | 1686 | | |
| |||
1828 | 1890 | | |
1829 | 1891 | | |
1830 | 1892 | | |
1831 | | - | |
| 1893 | + | |
1832 | 1894 | | |
1833 | 1895 | | |
1834 | 1896 | | |
| |||
0 commit comments