Commit 3f38609
authored
perf: Optimize replace() fastpath by avoiding alloc (#20344)
## Which issue does this PR close?
- Closes #20343.
## Rationale for this change
We already have a fastpath for when `from` and `to` are both single
ASCII characters, but this fastpath could be further optimized by
avoiding the `Vec<u8>` allocation.
## What changes are included in this PR?
Implement the described optimization.
## Are these changes tested?
Yes, no new tests or benchmarks warranted. This PR yields a 10-50%
performance improvement for the relevant microbenchmarks.
## Are there any user-facing changes?
No.1 parent f471aaf commit 3f38609
1 file changed
Lines changed: 11 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
232 | | - | |
| 231 | + | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
244 | 246 | | |
245 | 247 | | |
246 | 248 | | |
| |||
0 commit comments