Skip to content

Commit

Permalink
Auto merge of #82058 - gilescope:to_digit_speedup, r=lcnr
Browse files Browse the repository at this point in the history
no need to check assertion on fast path as will always hold.

V small change. Easy to review though!
  • Loading branch information
bors committed Feb 16, 2021
2 parents 090dac0 + b70428b commit f1c47c7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ impl char {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_digit(self, radix: u32) -> Option<u32> {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");

// the code is split up here to improve execution speed for cases where
// the `radix` is constant and 10 or smaller
let val = if radix <= 10 {
Expand All @@ -340,6 +338,8 @@ impl char {
_ => return None,
}
} else {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");

match self {
'0'..='9' => self as u32 - '0' as u32,
'a'..='z' => self as u32 - 'a' as u32 + 10,
Expand Down

0 comments on commit f1c47c7

Please sign in to comment.