Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e898257

Browse files
gilescopepickfire
andcommitted
Update library/core/src/num/mod.rs
Co-authored-by: Ivan Tham <[email protected]>
1 parent 70b04fd commit e898257

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/core/src/num/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,11 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
10961096
// sum of powers of 2 (x*10 can be written as x*8 + x*2).
10971097
// When the compiler can't use these optimisations,
10981098
// the latency of the multiplication can be hidden by issuing it
1099-
// before the result is needed.
1099+
// before the result is needed to improve performance on
1100+
// modern out-of-order CPU as multiplication here is slower
1101+
// than the other instructions, we can get the end result faster
1102+
// doing multiplication first and let the CPU spends other cycles
1103+
// doing other computation and get multiplication result later.
11001104
let mul = result.checked_mul(radix);
11011105
let x = (c as char).to_digit(radix).ok_or(PIE { kind: InvalidDigit })?;
11021106
result = mul.ok_or_else(overflow_err)?;

0 commit comments

Comments
 (0)