Skip to content

Commit

Permalink
Simplification (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilescope committed Jun 11, 2021
1 parent 0ac86ef commit 7c2a9b2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions uint/src/uint.rs
Expand Up @@ -603,12 +603,11 @@ macro_rules! construct_uint {

/// Convert from a decimal string.
pub fn from_dec_str(value: &str) -> $crate::core_::result::Result<Self, $crate::FromDecStrErr> {
if !value.bytes().all(|b| b >= 48 && b <= 57) {
return Err($crate::FromDecStrErr::InvalidCharacter)
}

let mut res = Self::default();
for b in value.bytes().map(|b| b - 48) {
for b in value.bytes().map(|b| b.wrapping_sub(b'0')) {
if b > 9 {
return Err($crate::FromDecStrErr::InvalidCharacter)
}
let (r, overflow) = res.overflowing_mul_u64(10);
if overflow > 0 {
return Err($crate::FromDecStrErr::InvalidLength);
Expand Down

0 comments on commit 7c2a9b2

Please sign in to comment.