refactor: avoid some allocations when redacting
This commit is contained in:
		
							parent
							
								
									04eee089e0
								
							
						
					
					
						commit
						940f533d61
					
				
					 1 changed files with 10 additions and 9 deletions
				
			
		
							
								
								
									
										19
									
								
								src/pdu.rs
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/pdu.rs
									
									
									
									
									
								
							|  | @ -37,11 +37,12 @@ pub struct PduEvent { | ||||||
| impl PduEvent { | impl PduEvent { | ||||||
|     pub fn redact(&mut self) -> Result<()> { |     pub fn redact(&mut self) -> Result<()> { | ||||||
|         self.unsigned.clear(); |         self.unsigned.clear(); | ||||||
|         let allowed = match self.kind { | 
 | ||||||
|             EventType::RoomMember => vec!["membership"], |         let allowed: &[&str] = match self.kind { | ||||||
|             EventType::RoomCreate => vec!["creator"], |             EventType::RoomMember => &["membership"], | ||||||
|             EventType::RoomJoinRules => vec!["join_rule"], |             EventType::RoomCreate => &["creator"], | ||||||
|             EventType::RoomPowerLevels => vec![ |             EventType::RoomJoinRules => &["join_rule"], | ||||||
|  |             EventType::RoomPowerLevels => &[ | ||||||
|                 "ban", |                 "ban", | ||||||
|                 "events", |                 "events", | ||||||
|                 "events_default", |                 "events_default", | ||||||
|  | @ -51,8 +52,8 @@ impl PduEvent { | ||||||
|                 "users", |                 "users", | ||||||
|                 "users_default", |                 "users_default", | ||||||
|             ], |             ], | ||||||
|             EventType::RoomHistoryVisibility => vec!["history_visibility"], |             EventType::RoomHistoryVisibility => &["history_visibility"], | ||||||
|             _ => vec![], |             _ => &[], | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         let old_content = self |         let old_content = self | ||||||
|  | @ -63,8 +64,8 @@ impl PduEvent { | ||||||
|         let mut new_content = serde_json::Map::new(); |         let mut new_content = serde_json::Map::new(); | ||||||
| 
 | 
 | ||||||
|         for key in allowed { |         for key in allowed { | ||||||
|             if let Some(value) = old_content.remove(key) { |             if let Some(value) = old_content.remove(*key) { | ||||||
|                 new_content.insert(key.to_owned(), value); |                 new_content.insert((*key).to_owned(), value); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue