Skip to content

Commit b1601a0

Browse files
committed
vmstat: optimize
1 parent 389a9f6 commit b1601a0

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

src/uu/vmstat/src/picker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn with_unit(x: u64, arg: &ArgMatches) -> u64 {
7373
"K" => x / bytesize::KIB,
7474
"m" => x / bytesize::MB,
7575
"M" => x / bytesize::MIB,
76-
_ => x, // impossible
76+
_ => unreachable!(),
7777
};
7878
}
7979
x / bytesize::KIB

src/uu/vmstat/src/vmstat.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
4141

4242
let delay = matches.get_one::<u64>("delay");
4343
let count = matches.get_one::<u64>("count");
44-
let mut count = if let Some(count) = count {
45-
if *count == 0 {
46-
Some(1)
47-
} else {
48-
Some(*count)
49-
}
50-
} else {
51-
None
52-
};
53-
let delay = if let Some(delay) = delay {
54-
*delay
55-
} else {
56-
if count.is_none() {
57-
count = Some(1);
58-
}
44+
let mut count = count.copied().map(|c| if c == 0 { 1 } else { c });
45+
let delay = delay.copied().unwrap_or_else(|| {
46+
count.get_or_insert(1);
5947
1
60-
};
48+
});
6149

6250
let pickers = get_pickers(&matches);
6351
let mut proc_data = ProcData::new();

0 commit comments

Comments
 (0)