Replace manual binary search with stdlib (#1466)
This commit is contained in:
parent
6a2d6fa66d
commit
0a0c4639a6
@ -1922,35 +1922,6 @@ where
|
|||||||
shmem_provider: SP,
|
shmem_provider: SP,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn binary_search<SP: ShMemProvider>(
|
|
||||||
llmp_clients: &Vec<LlmpReceiver<SP>>,
|
|
||||||
client_id: ClientId,
|
|
||||||
) -> Option<usize> {
|
|
||||||
if llmp_clients.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut left = 0;
|
|
||||||
let mut right = llmp_clients.len().checked_sub(1)?;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if left > right {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mid = left + (right - left) / 2;
|
|
||||||
|
|
||||||
match client_id {
|
|
||||||
id if id == llmp_clients[mid].id => return Some(llmp_clients[mid].id.0 as _),
|
|
||||||
id if id > llmp_clients[mid].id => left = mid + 1,
|
|
||||||
_ => right = mid.checked_sub(1).expect("invalid right edge"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A signal handler for the [`LlmpBroker`].
|
/// A signal handler for the [`LlmpBroker`].
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -2715,8 +2686,9 @@ where
|
|||||||
// Fast path when no client was removed
|
// Fast path when no client was removed
|
||||||
client_id.0 as usize
|
client_id.0 as usize
|
||||||
} else {
|
} else {
|
||||||
binary_search(&self.llmp_clients, client_id)
|
self.llmp_clients
|
||||||
.expect("Fatal error, client ID not found")
|
.binary_search_by_key(&client_id, |x| x.id)
|
||||||
|
.expect("Fatal error, client ID {client_id} not found in llmp_clients.")
|
||||||
};
|
};
|
||||||
let client = &mut self.llmp_clients[pos];
|
let client = &mut self.llmp_clients[pos];
|
||||||
match client.recv()? {
|
match client.recv()? {
|
||||||
@ -2799,8 +2771,9 @@ where
|
|||||||
// Fast path when no client was removed
|
// Fast path when no client was removed
|
||||||
client_id.0 as usize
|
client_id.0 as usize
|
||||||
} else {
|
} else {
|
||||||
binary_search(&self.llmp_clients, client_id)
|
self.llmp_clients
|
||||||
.expect("Fatal error, client ID not found")
|
.binary_search_by_key(&client_id, |x| x.id)
|
||||||
|
.expect("Fatal error, client ID {client_id} not found in llmp_clients.")
|
||||||
};
|
};
|
||||||
|
|
||||||
let map = &mut self.llmp_clients[pos].current_recv_shmem;
|
let map = &mut self.llmp_clients[pos].current_recv_shmem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user