mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Optimize next_timeout slightly
Avoid moves as it apparently adversely affects perf
This commit is contained in:
parent
3158a2c73b
commit
8327d327c1
@ -231,21 +231,22 @@ impl<T> TimerWheel<T> {
|
||||
/// scheduled in this wheel.
|
||||
pub fn next_timeout(&self) -> Option<Instant> {
|
||||
// TODO: can this be optimized to not look at the whole array?
|
||||
let timeouts = self.wheel.iter().map(|slot| slot.next_timeout);
|
||||
let min = timeouts.fold(None, |prev, cur| {
|
||||
match (prev, cur) {
|
||||
(None, cur) => cur,
|
||||
(Some(time), None) => Some(time),
|
||||
(Some(a), Some(b)) => Some(cmp::min(a, b)),
|
||||
let mut min = None;
|
||||
for a in self.wheel.iter().filter_map(|s| s.next_timeout.as_ref()) {
|
||||
if let Some(b) = min {
|
||||
if b < a {
|
||||
continue
|
||||
}
|
||||
}
|
||||
});
|
||||
min = Some(a);
|
||||
}
|
||||
if let Some(min) = min {
|
||||
debug!("next timeout {:?}", min);
|
||||
debug!("now {:?}", Instant::now());
|
||||
} else {
|
||||
debug!("next timeout never");
|
||||
}
|
||||
return min
|
||||
min.map(|t| *t)
|
||||
}
|
||||
|
||||
/// Cancels the specified timeout.
|
||||
|
Loading…
x
Reference in New Issue
Block a user