From f147716e7d5a3b4e1e4c0e8b5b5dd26da00cdab0 Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Sun, 20 Jul 2025 05:33:25 +0000 Subject: [PATCH] flt2dec: use fill instead of loop --- library/core/src/num/flt2dec/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/library/core/src/num/flt2dec/mod.rs b/library/core/src/num/flt2dec/mod.rs index 7601e3e2c58a2..e79a00a865969 100644 --- a/library/core/src/num/flt2dec/mod.rs +++ b/library/core/src/num/flt2dec/mod.rs @@ -150,23 +150,19 @@ pub fn round_up(d: &mut [u8]) -> Option { Some(i) => { // d[i+1..n] is all nines d[i] += 1; - for j in i + 1..d.len() { - d[j] = b'0'; - } + d[i + 1..].fill(b'0'); None } - None if d.len() > 0 => { + None if d.is_empty() => { + // an empty buffer rounds up (a bit strange but reasonable) + Some(b'1') + } + None => { // 999..999 rounds to 1000..000 with an increased exponent d[0] = b'1'; - for j in 1..d.len() { - d[j] = b'0'; - } + d[1..].fill(b'0'); Some(b'0') } - None => { - // an empty buffer rounds up (a bit strange but reasonable) - Some(b'1') - } } }