Skip to content

Commit 3878e8e

Browse files
committed
Improve code quality
1 parent f124ec8 commit 3878e8e

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

common/src/float_ops.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ fn remove_trailing_zeros(s: String) -> String {
149149
pub fn format_general(precision: usize, magnitude: f64, case: Case) -> String {
150150
match magnitude {
151151
magnitude if magnitude.is_finite() => {
152-
let prec = match precision {
153-
0 => 0,
154-
_ => precision - 1,
155-
};
156-
let r_exp = format!("{:.*e}", prec, magnitude);
152+
let r_exp = format!("{:.*e}", precision.saturating_sub(1), magnitude);
157153
let mut parts = r_exp.splitn(2, 'e');
158154
let base = parts.next().unwrap();
159155
let exponent = parts.next().unwrap().parse::<i64>().unwrap();

vm/src/builtins/pystr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ impl PyIter for PyStrReverseIterator {
180180
break;
181181
}
182182
}
183-
if end < 4 {
184-
start.unwrap_or(0)
185-
} else {
186-
start.unwrap_or(end - 4)
187-
}
183+
start.unwrap_or_else(|| end.saturating_sub(4))
188184
};
189185

190186
let stored = zelf.position.swap(start);

0 commit comments

Comments
 (0)