From cba01446126b37d70e49ddbc4eda1ba36da4e6a4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 22 Mar 2021 08:54:44 -0700 Subject: [PATCH] Use `min_by` instead of `sort_by` when we only want the minimum element. This is just a minor code simplification I happened to notice while doing unrelated work on `poll_oneoff`. --- crates/wasi-common/src/sched.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/wasi-common/src/sched.rs b/crates/wasi-common/src/sched.rs index db2a81f9db..a925cd4e94 100644 --- a/crates/wasi-common/src/sched.rs +++ b/crates/wasi-common/src/sched.rs @@ -67,16 +67,13 @@ impl<'a> Poll<'a> { self.subs.is_empty() } pub fn earliest_clock_deadline(&'a self) -> Option<&MonotonicClockSubscription<'a>> { - let mut subs = self - .subs + self.subs .iter() .filter_map(|(s, _ud)| match s { Subscription::MonotonicClock(t) => Some(t), _ => None, }) - .collect::>>(); - subs.sort_by(|a, b| a.deadline.cmp(&b.deadline)); - subs.into_iter().next() // First element is earliest + .min_by(|a, b| a.deadline.cmp(&b.deadline)) } pub fn rw_subscriptions(&'a self) -> impl Iterator> { self.subs.iter().filter_map(|(s, _ud)| match s {