You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize is_ascii_digit() and is_ascii_hexdigit()
The current implementation of these two functions does redundant checks
that are currently not optimized away by LLVM. The is_digit() method
on char only matches ASCII digits. It does not do the extra check of
whether the character is in ASCII range.
This change optimizes the code in both debug and release mode on various
major architectures. It removes all conditional branches on x86 and all
conditional branches and returns on ARM.
Pseudocode version of LLVM's optimized output:
old version:
```rust
if c >= 128 { return false; }
c -= 48;
if c > 9 { return false; }
true
```
new version:
```rust
c -= 48;
if c < 10 { return true; }
false
```
The is_ascii_hexdigit() change similarly shortens the emitted code in
release mode. The optimized version uses bit manipulation to remove one
comparison and conditional branch. It would be possible to add a similar
change to the is_digit() code, but that has not been done yet.
Godbolt comparison between the two implementations:
https://godbolt.org/z/gDwfSF
0 commit comments