Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c0b282f

Browse files
committed
Auto merge of #144205 - hkBst:flt2dec, r=workingjubilee
flt2dec: replace for loop by iter_mut Perf is explored in #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.
2 parents 9748d87 + f147716 commit c0b282f

File tree

1 file changed

+7
-11
lines changed
  • library/core/src/num/flt2dec

1 file changed

+7
-11
lines changed

‎library/core/src/num/flt2dec/mod.rs‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,19 @@ pub fn round_up(d: &mut [u8]) -> Option<u8> {
150150
Some(i) => {
151151
// d[i+1..n] is all nines
152152
d[i] += 1;
153-
for j in i + 1..d.len() {
154-
d[j] = b'0';
155-
}
153+
d[i + 1..].fill(b'0');
156154
None
157155
}
158-
None if d.len() > 0 => {
156+
None if d.is_empty() => {
157+
// an empty buffer rounds up (a bit strange but reasonable)
158+
Some(b'1')
159+
}
160+
None => {
159161
// 999..999 rounds to 1000..000 with an increased exponent
160162
d[0] = b'1';
161-
for j in 1..d.len() {
162-
d[j] = b'0';
163-
}
163+
d[1..].fill(b'0');
164164
Some(b'0')
165165
}
166-
None => {
167-
// an empty buffer rounds up (a bit strange but reasonable)
168-
Some(b'1')
169-
}
170166
}
171167
}
172168

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /