rust/src/libcore
Pietro Albini f40f04bcc1
Rollup merge of #55932 - Turbo87:to_digit, r=alexcrichton
core/char: Speed up `to_digit()` for `radix <= 10`

I noticed that `char::to_digit()` seemed to do a bit of extra work for handling `[a-zA-Z]` characters. Since `to_digit(10)` seems to be the most common case (at least in the `rust` codebase) I thought it might be valuable to create a fast path for that case, and according to the benchmarks that I added in one of the commits it seems to pay off. I also created another fast path for the `radix < 10` case, which also seems to have a positive effect.

It is very well possible that I'm measuring something entirely unrelated though, so please verify these numbers and let me know if I missed something!

### Before

```
# Run 1
test char::methods::bench_to_digit_radix_10      ... bench:      16,265 ns/iter (+/- 1,774)
test char::methods::bench_to_digit_radix_16      ... bench:      13,938 ns/iter (+/- 2,479)
test char::methods::bench_to_digit_radix_2       ... bench:      13,090 ns/iter (+/- 524)
test char::methods::bench_to_digit_radix_36      ... bench:      14,236 ns/iter (+/- 1,949)

# Run 2
test char::methods::bench_to_digit_radix_10      ... bench:      16,176 ns/iter (+/- 1,589)
test char::methods::bench_to_digit_radix_16      ... bench:      13,896 ns/iter (+/- 3,140)
test char::methods::bench_to_digit_radix_2       ... bench:      13,158 ns/iter (+/- 1,112)
test char::methods::bench_to_digit_radix_36      ... bench:      14,206 ns/iter (+/- 1,312)

# Run 3
test char::methods::bench_to_digit_radix_10      ... bench:      16,221 ns/iter (+/- 2,423)
test char::methods::bench_to_digit_radix_16      ... bench:      14,361 ns/iter (+/- 3,926)
test char::methods::bench_to_digit_radix_2       ... bench:      13,097 ns/iter (+/- 671)
test char::methods::bench_to_digit_radix_36      ... bench:      14,388 ns/iter (+/- 1,068)
```

### After

```
# Run 1
test char::methods::bench_to_digit_radix_10      ... bench:      11,521 ns/iter (+/- 552)
test char::methods::bench_to_digit_radix_16      ... bench:      12,926 ns/iter (+/- 684)
test char::methods::bench_to_digit_radix_2       ... bench:      11,266 ns/iter (+/- 1,085)
test char::methods::bench_to_digit_radix_36      ... bench:      14,213 ns/iter (+/- 614)

# Run 2
test char::methods::bench_to_digit_radix_10      ... bench:      11,424 ns/iter (+/- 1,042)
test char::methods::bench_to_digit_radix_16      ... bench:      12,854 ns/iter (+/- 1,193)
test char::methods::bench_to_digit_radix_2       ... bench:      11,193 ns/iter (+/- 716)
test char::methods::bench_to_digit_radix_36      ... bench:      14,249 ns/iter (+/- 3,514)

# Run 3
test char::methods::bench_to_digit_radix_10      ... bench:      11,469 ns/iter (+/- 685)
test char::methods::bench_to_digit_radix_16      ... bench:      12,852 ns/iter (+/- 568)
test char::methods::bench_to_digit_radix_2       ... bench:      11,275 ns/iter (+/- 1,356)
test char::methods::bench_to_digit_radix_36      ... bench:      14,188 ns/iter (+/- 1,501)
```

I ran the benchmark using:

```sh
python x.py bench src/libcore --stage 1 --keep-stage 0 --test-args "bench_to_digit"
```
2018-11-15 11:04:46 +01:00
..
benches core/benches: Add char::to_digit() benchmarks 2018-11-13 22:02:51 +01:00
char core/char: Add comment to to_digit() 2018-11-14 11:26:00 +01:00
fmt revert spurious edits. 2018-11-10 02:33:21 +01:00
future Fix documentation typos. 2018-11-10 19:31:49 +07:00
hash Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
iter Rollup merge of #55896 - rust-lang:opt-fuse, r=shepmaster 2018-11-13 19:20:58 +08:00
num Rollup merge of #55901 - euclio:speling, r=petrochenkov 2018-11-15 11:04:42 +01:00
ops constify parts of libcore. 2018-11-10 01:07:32 +01:00
prelude Drop identity from prelude. 2018-08-19 18:36:18 +02:00
slice revert making internal APIs const fn. 2018-11-10 01:10:07 +01:00
str Rollup merge of #55870 - waywardmonkeys:typo-fixes, r=wesleywiser 2018-11-13 19:20:44 +08:00
sync Do not Atomic{I,U}128 in stage0 2018-11-05 18:54:17 +02:00
task fix various typos in doc comments 2018-11-13 14:45:31 -05:00
tests Bump nightly to 1.32.0 2018-10-31 11:53:50 -07:00
unicode revert making internal APIs const fn. 2018-11-10 01:10:07 +01:00
alloc.rs Rollup merge of #55844 - waywardmonkeys:typo-fixes, r=varkor 2018-11-11 00:21:25 +01:00
any.rs Enforce #![deny(bare_trait_objects)] in src/libcore 2018-07-25 10:21:41 +09:00
array.rs revert making internal APIs const fn. 2018-11-10 01:10:07 +01:00
ascii.rs migrate codebase to ..= inclusive range patterns 2018-06-26 07:53:30 -07:00
borrow.rs Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
Cargo.toml Breaking change upgrades 2018-09-04 13:22:08 -06:00
cell.rs revert making internal APIs const fn. 2018-11-10 01:10:07 +01:00
clone.rs Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
cmp.rs Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
convert.rs constify parts of libcore. 2018-11-10 01:07:32 +01:00
default.rs Made doc example of impl Default for … use -> Self instead of explicit self type 2018-11-01 11:52:44 +01:00
ffi.rs Move std::os::raw::c_void into libcore and re-export in libstd 2018-09-14 16:19:59 +01:00
hint.rs Stabilize core::hint::unreachable_unchecked. 2018-04-16 18:29:40 +08:00
internal_macros.rs Switch to 1.26 bootstrap compiler 2018-05-17 08:47:25 -06:00
intrinsics.rs Rollup merge of #55785 - stjepang:unsized-drop-forget, r=alexcrichton 2018-11-15 11:04:38 +01:00
iter_private.rs Various fixes to wording consistency in the docs 2017-03-22 17:19:52 +01:00
lib.rs Rollup merge of #55785 - stjepang:unsized-drop-forget, r=alexcrichton 2018-11-15 11:04:38 +01:00
macros.rs Fix docstring spelling mistakes 2018-11-09 23:14:46 -05:00
marker.rs make PhantomData #[structural_match]. 2018-11-10 03:39:42 +01:00
mem.rs Rollup merge of #55785 - stjepang:unsized-drop-forget, r=alexcrichton 2018-11-15 11:04:38 +01:00
nonzero.rs Replace CoerceSized trait with DispatchFromDyn 2018-11-01 18:16:59 -04:00
option.rs Bump the Option::replace stabilize version to 1.31.0 2018-10-08 10:18:43 +02:00
panic.rs reduce list to functions callable in const ctx. 2018-11-10 01:10:07 +01:00
panicking.rs Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
pin.rs Fix docstring spelling mistakes 2018-11-09 23:14:46 -05:00
ptr.rs Auto merge of #55278 - Centril:constification-1, r=alexcrichton 2018-11-12 18:54:11 +00:00
raw.rs Fix up various links 2017-03-20 10:10:16 -04:00
result.rs Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
time.rs constify parts of libstd. 2018-11-10 01:10:07 +01:00
tuple.rs Update bootstrap compiler 2017-08-31 06:58:58 -07:00
unit.rs impl FromIterator<()> for () 2017-10-18 23:12:37 -07:00