1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

do not reallocate waiters

This commit is contained in:
Nikolay Kim 2018-07-20 10:20:41 -07:00
parent 0925a7691a
commit 2043bb5ece

View File

@ -509,28 +509,30 @@ impl ClientConnector {
} }
} }
// TODO: waiters should be sorted by deadline. maybe timewheel?
fn collect_waiters(&mut self) { fn collect_waiters(&mut self) {
let now = Instant::now(); let now = Instant::now();
let mut next = None; let mut next = None;
for waiters in self.waiters.as_mut().unwrap().values_mut() { for waiters in self.waiters.as_mut().unwrap().values_mut() {
let mut new_waiters = VecDeque::new(); let mut idx = 0;
while let Some(waiter) = waiters.pop_front() { while idx < waiters.len() {
if waiter.wait <= now { let wait = waiters[idx].wait;
if wait <= now {
self.stats.timeouts += 1; self.stats.timeouts += 1;
let waiter = waiters.swap_remove_back(idx).unwrap();
let _ = waiter.tx.send(Err(ClientConnectorError::Timeout)); let _ = waiter.tx.send(Err(ClientConnectorError::Timeout));
} else { } else {
if let Some(n) = next { if let Some(n) = next {
if waiter.wait < n { if wait < n {
next = Some(waiter.wait); next = Some(wait);
} }
} else { } else {
next = Some(waiter.wait); next = Some(wait);
} }
new_waiters.push_back(waiter); idx += 1;
} }
} }
*waiters = new_waiters;
} }
if next.is_some() { if next.is_some() {