Skip to content

Commit

Permalink
Rollup merge of rust-lang#96124 - gilescope:to_digit_speedup4, r=thomcc
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Dylan-DPC authored Apr 16, 2022
2 parents 2da2934 + bf02d1e commit b45a233
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b45a233

Please sign in to comment.