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`.
This commit is contained in:
@@ -67,16 +67,13 @@ impl<'a> Poll<'a> {
|
|||||||
self.subs.is_empty()
|
self.subs.is_empty()
|
||||||
}
|
}
|
||||||
pub fn earliest_clock_deadline(&'a self) -> Option<&MonotonicClockSubscription<'a>> {
|
pub fn earliest_clock_deadline(&'a self) -> Option<&MonotonicClockSubscription<'a>> {
|
||||||
let mut subs = self
|
self.subs
|
||||||
.subs
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(s, _ud)| match s {
|
.filter_map(|(s, _ud)| match s {
|
||||||
Subscription::MonotonicClock(t) => Some(t),
|
Subscription::MonotonicClock(t) => Some(t),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.collect::<Vec<&MonotonicClockSubscription<'a>>>();
|
.min_by(|a, b| a.deadline.cmp(&b.deadline))
|
||||||
subs.sort_by(|a, b| a.deadline.cmp(&b.deadline));
|
|
||||||
subs.into_iter().next() // First element is earliest
|
|
||||||
}
|
}
|
||||||
pub fn rw_subscriptions(&'a self) -> impl Iterator<Item = &Subscription<'a>> {
|
pub fn rw_subscriptions(&'a self) -> impl Iterator<Item = &Subscription<'a>> {
|
||||||
self.subs.iter().filter_map(|(s, _ud)| match s {
|
self.subs.iter().filter_map(|(s, _ud)| match s {
|
||||||
|
|||||||
Reference in New Issue
Block a user