about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-22 08:28:29 +0000
committerbors <bors@rust-lang.org>2025-07-22 08:28:29 +0000
commitc0b282f0ccdab7523cdb8dfa41b23bed5573da76 (patch)
tree7da989c238ce74cfb6d30dacbaafe17a21672bdd /library/core/src
parent9748d87dc70a9a6725c5dbd76ce29d04752b4f90 (diff)
parentf147716e7d5a3b4e1e4c0e8b5b5dd26da00cdab0 (diff)
downloadrust-c0b282f0ccdab7523cdb8dfa41b23bed5573da76.tar.gz
rust-c0b282f0ccdab7523cdb8dfa41b23bed5573da76.zip
Auto merge of #144205 - hkBst:flt2dec, r=workingjubilee
flt2dec: replace for loop by iter_mut

Perf is explored in https://github.com/rust-lang/rust/issues/144118, which initially showed small losses, but then also showed significant gains. Both are real, but given the smallness of the losses, this seems a good change.
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/num/flt2dec/mod.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/library/core/src/num/flt2dec/mod.rs b/library/core/src/num/flt2dec/mod.rs
index 7601e3e2c58..e79a00a8659 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<u8> {
         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')
-        }
     }
 }