Rollup merge of #96124 - gilescope:to_digit_speedup4, r=thomcc

to_digit tweak

No need to check the assert all the time.

(Checked the TODO and it's not time to get rid of it yet)
This commit is contained in:
Dylan DPC 2022-04-17 00:07:28 +02:00 committed by GitHub
commit b47265e658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -343,10 +343,10 @@ impl char {
without modifying the original"]
#[inline]
pub const fn to_digit(self, radix: u32) -> Option<u32> {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
// If not a digit, a number greater than radix will be created.
let mut digit = (self as u32).wrapping_sub('0' as u32);
if radix > 10 {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
if digit < 10 {
return Some(digit);
}