init a few vecs in event_handler using with_capacity

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-05-16 23:54:54 -04:00 committed by June 🍓🦴
parent d49507bc21
commit e098448b9d
2 changed files with 6 additions and 6 deletions

View File

@ -163,7 +163,7 @@ pub(crate) async fn get_context_route(body: Ruma<get_context::v3::Request>) -> R
.map(|(_, pdu)| pdu.to_room_event())
.collect();
let mut state = Vec::new();
let mut state = Vec::with_capacity(state_ids.len());
for (shortstatekey, id) in state_ids {
let (event_type, state_key) = services()

View File

@ -674,7 +674,7 @@ impl Service {
let fork_states = [current_state_ids, incoming_state];
let mut auth_chain_sets = Vec::new();
let mut auth_chain_sets = Vec::with_capacity(fork_states.len());
for state in &fork_states {
auth_chain_sets.push(
services()
@ -1007,7 +1007,7 @@ impl Service {
}
};
let mut events_with_auth_events = vec![];
let mut events_with_auth_events = Vec::with_capacity(events.len());
for id in events {
// a. Look in the main timeline (pduid_pdu tree)
// b. Look at outlier pdu tree
@ -1022,8 +1022,8 @@ impl Service {
// We also handle its auth chain here so we don't get a stack overflow in
// handle_outlier_pdu.
let mut todo_auth_events = vec![Arc::clone(id)];
let mut events_in_reverse_order = Vec::new();
let mut events_all = HashSet::new();
let mut events_in_reverse_order = Vec::with_capacity(todo_auth_events.len());
let mut events_all = HashSet::with_capacity(todo_auth_events.len());
let mut i = 0;
while let Some(next_id) = todo_auth_events.pop() {
if let Some((time, tries)) = services()
@ -1124,7 +1124,7 @@ impl Service {
warn!("Could not fetch all signatures for PDUs from {}: {:?}", origin, e);
});
let mut pdus = vec![];
let mut pdus = Vec::with_capacity(events_with_auth_events.len());
for (id, local_pdu, events_in_reverse_order) in events_with_auth_events {
// a. Look in the main timeline (pduid_pdu tree)
// b. Look at outlier pdu tree