From 940f533d6187a4178786762b7063d7931c6fb9e5 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 12 Aug 2020 15:33:45 +0200 Subject: [PATCH] refactor: avoid some allocations when redacting --- src/pdu.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pdu.rs b/src/pdu.rs index b689a3e..9936802 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -37,11 +37,12 @@ pub struct PduEvent { impl PduEvent { pub fn redact(&mut self) -> Result<()> { self.unsigned.clear(); - let allowed = match self.kind { - EventType::RoomMember => vec!["membership"], - EventType::RoomCreate => vec!["creator"], - EventType::RoomJoinRules => vec!["join_rule"], - EventType::RoomPowerLevels => vec![ + + let allowed: &[&str] = match self.kind { + EventType::RoomMember => &["membership"], + EventType::RoomCreate => &["creator"], + EventType::RoomJoinRules => &["join_rule"], + EventType::RoomPowerLevels => &[ "ban", "events", "events_default", @@ -51,8 +52,8 @@ impl PduEvent { "users", "users_default", ], - EventType::RoomHistoryVisibility => vec!["history_visibility"], - _ => vec![], + EventType::RoomHistoryVisibility => &["history_visibility"], + _ => &[], }; let old_content = self @@ -63,8 +64,8 @@ impl PduEvent { let mut new_content = serde_json::Map::new(); for key in allowed { - if let Some(value) = old_content.remove(key) { - new_content.insert(key.to_owned(), value); + if let Some(value) = old_content.remove(*key) { + new_content.insert((*key).to_owned(), value); } }