From d27454eda51a946a5f80c30b836238821b1f56fc Mon Sep 17 00:00:00 2001 From: gilescope Date: Sat, 26 Mar 2022 14:53:56 +0000 Subject: [PATCH] Using macro to avoid performance hit (thanks LingMan) --- library/core/src/num/mod.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index a398fe4a8b6..4a73329e7b9 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1078,14 +1078,20 @@ fn from_str_radix(src: &str, radix: u32) -> Result { + for &c in digits { + result = result.unchecked_mul(radix); + let x = (c as char).to_digit(radix).ok_or(PIE { kind: InvalidDigit })?; + result = T::$unchecked_additive_op(&result, x); + } + }; } + if is_positive { + run_loop!(unchecked_add) + } else { + run_loop!(unchecked_sub) + }; } } else { let additive_op = if is_positive { T::checked_add } else { T::checked_sub };