]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #81837 - gilescope:to_ascii_speedups, r=dtolnay
authorDylan DPC <dylan.dpc@gmail.com>
Tue, 23 Feb 2021 01:51:47 +0000 (02:51 +0100)
committerGitHub <noreply@github.com>
Tue, 23 Feb 2021 01:51:47 +0000 (02:51 +0100)
commit4af965e73262190137a86b44fc2f75da7fb54eab
tree8b4fe6abf3e045534c80c7771b860f77b6eb1337
parent5d90e89c36468350b9636614b0f9dbf64a4aef80
parent33d8b0456876181883f8d97997a3a0a6e9ff652f
Rollup merge of #81837 - gilescope:to_ascii_speedups, r=dtolnay

Slight perf improvement on char::to_ascii_lowercase

`char::to_ascii_lowercase()` was checking if it was ascii and then if it was in the right range. Instead propose to check once (I think removing a compare and a shift in the process: [godbolt](https://godbolt.org/z/e5Tora) ).

before:
```
        test char::methods::bench_to_ascii_lowercase                    ... bench:      11,196 ns/iter (+/- 632)
        test char::methods::bench_to_ascii_uppercase                    ... bench:      11,656 ns/iter (+/- 671)
```
after:
```
         test char::methods::bench_to_ascii_lowercase                    ... bench:       9,612 ns/iter (+/- 979)
         test char::methods::bench_to_ascii_uppercase                    ... bench:       8,241 ns/iter (+/- 701)
```

(calling u8::to_ascii_lowercase and letting that flip the 5th bit is also an option, but it's more instructions. I'm thinking for things around ascii and char we want to be as efficient as possible.)
library/core/src/char/methods.rs