Commit 5515a97
committed
Introduce a special case in
The `if let Some(val) = value.try_eval_bits(...)` branch in `from_const()` is
very hot for the `unicode_normalization` benchmark.
This commit introduces a special-case alternative for scalars that avoids
`try_eval_bits()` and all the functions it calls (`Const::eval()`,
`ConstValue::try_to_bits()`, `ConstValue::try_to_scalar()`, and
`Scalar::to_bits()`), instead extracting the result immediately.
The type and value checking done by `Scalar::to_bits()` is replicated by moving
it into a new function `Scalar::check_raw()` and using that new function in the
special case.
PR rust-lang#64673 introduced some special-case handling of scalar types in
`Const::try_eval_bits()`. This handling is now moved out of that function into
the new `IntRange::integral_size_and_signed_bias` function.
This commit reduces the instruction count for
`unicode_normalization-check-clean` by about 10%.IntRange::from_const.1 parent a69e0e0 commit 5515a97
3 files changed
+38
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
346 | 353 | | |
347 | 354 | | |
348 | 355 | | |
349 | 356 | | |
350 | 357 | | |
351 | | - | |
352 | | - | |
353 | | - | |
| 358 | + | |
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
2299 | 2298 | | |
2300 | 2299 | | |
2301 | 2300 | | |
2302 | | - | |
2303 | | - | |
2304 | | - | |
2305 | | - | |
2306 | | - | |
2307 | | - | |
2308 | | - | |
2309 | | - | |
2310 | | - | |
2311 | | - | |
2312 | | - | |
2313 | | - | |
2314 | | - | |
2315 | | - | |
| 2301 | + | |
2316 | 2302 | | |
2317 | 2303 | | |
2318 | 2304 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
845 | 858 | | |
846 | 859 | | |
847 | 860 | | |
848 | 861 | | |
849 | 862 | | |
850 | 863 | | |
851 | | - | |
| 864 | + | |
852 | 865 | | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
857 | 876 | | |
858 | | - | |
859 | | - | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
860 | 881 | | |
861 | 882 | | |
862 | 883 | | |
| |||
0 commit comments