perf: use unstable sorting when async
Unstable sorting should be slightly faster than stable sorting, and if the vector was built asynchronously then preserving the initial order doesn't matter too much. Continue to use stable sorting where the vector is not built asynchronously, or if the vector is partially sorted (e.g. when new elements are pushed to a sorted vector).
This commit is contained in:
parent
dd0158d8f0
commit
38c037c977
5 changed files with 6 additions and 6 deletions
|
|
@ -77,7 +77,7 @@ pub async fn handle_wireless_device(
|
|||
);
|
||||
}
|
||||
let mut aps = aps.into_values().collect::<Vec<_>>();
|
||||
aps.sort_by_key(|ap| ap.strength);
|
||||
aps.sort_unstable_by_key(|ap| ap.strength);
|
||||
Ok(aps)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ pub async fn active_connections(
|
|||
}
|
||||
}
|
||||
|
||||
info.sort();
|
||||
info.sort_unstable();
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ impl NetworkManagerState {
|
|||
let s = NetworkManagerSettings::new(conn).await?;
|
||||
_ = s.load_connections(&[]).await;
|
||||
let known_conns = s.list_connections().await.unwrap_or_default();
|
||||
let mut active_conns = active_connections(
|
||||
let active_conns = active_connections(
|
||||
network_manager
|
||||
.active_connections()
|
||||
.await
|
||||
|
|
@ -428,7 +428,7 @@ impl NetworkManagerState {
|
|||
)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
active_conns.sort();
|
||||
// active_conns.sort(); active_connections should have already sorted the vector
|
||||
let devices = network_manager.devices().await.ok().unwrap_or_default();
|
||||
let wireless_access_point_futures: Vec<_> = devices
|
||||
.into_iter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue