From 43432189578bc6327566748c24866c838358c6cc Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 17 Jul 2024 07:39:14 +0000 Subject: [PATCH] initialize some containers with_capacity Signed-off-by: Jason Volk --- src/service/sending/send.rs | 2 +- src/service/sending/sender.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/service/sending/send.rs b/src/service/sending/send.rs index df3139c3..7901de48 100644 --- a/src/service/sending/send.rs +++ b/src/service/sending/send.rs @@ -154,7 +154,7 @@ fn sign_request(dest: &ServerName, http_request: &mut http::Request>) where T: OutgoingRequest + Debug + Send, { - let mut req_map = serde_json::Map::new(); + let mut req_map = serde_json::Map::with_capacity(8); if !http_request.body().is_empty() { req_map.insert( "content".to_owned(), diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index df41db28..774c3d69 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -555,8 +555,18 @@ async fn send_events_dest_push( async fn send_events_dest_normal( dest: &Destination, server: &OwnedServerName, events: Vec, ) -> SendingResult { - let mut edu_jsons = Vec::new(); - let mut pdu_jsons = Vec::new(); + let mut pdu_jsons = Vec::with_capacity( + events + .iter() + .filter(|event| matches!(event, SendingEvent::Pdu(_))) + .count(), + ); + let mut edu_jsons = Vec::with_capacity( + events + .iter() + .filter(|event| matches!(event, SendingEvent::Edu(_))) + .count(), + ); for event in &events { match event {