From 3830dcddc22239b0a3f051ac3df5ed42ecc768b7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 13 Sep 2021 15:40:54 +0200 Subject: [PATCH] state-res: Simplify tests a bit --- .../ruma-state-res/benches/state_res_bench.rs | 18 +++++++++--------- crates/ruma-state-res/src/lib.rs | 8 ++------ crates/ruma-state-res/src/test_utils.rs | 8 +++----- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/crates/ruma-state-res/benches/state_res_bench.rs b/crates/ruma-state-res/benches/state_res_bench.rs index b3a5e354..707e4248 100644 --- a/crates/ruma-state-res/benches/state_res_bench.rs +++ b/crates/ruma-state-res/benches/state_res_bench.rs @@ -68,9 +68,7 @@ fn resolution_shallow_auth_chain(c: &mut Criterion) { state_sets .iter() .map(|map| { - store - .auth_event_ids(&room_id(), &map.values().cloned().collect::>()) - .unwrap() + store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| ev_map.get(id).map(Arc::clone), @@ -134,9 +132,7 @@ fn resolve_deeper_event_set(c: &mut Criterion) { state_sets .iter() .map(|map| { - store - .auth_event_ids(&room_id(), &map.values().cloned().collect::>()) - .unwrap() + store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| inner.get(id).map(Arc::clone), @@ -183,9 +179,13 @@ impl TestStore { } /// Returns a Vec of the related auth events to the given `event`. - fn auth_event_ids(&self, room_id: &RoomId, event_ids: &[EventId]) -> Result> { + fn auth_event_ids( + &self, + room_id: &RoomId, + event_ids: Vec, + ) -> Result> { let mut result = HashSet::new(); - let mut stack = event_ids.to_vec(); + let mut stack = event_ids; // DFS for auth event chain while !stack.is_empty() { @@ -214,7 +214,7 @@ impl TestStore { for ids in event_ids { // TODO state store `auth_event_ids` returns self in the event ids list // when an event returns `auth_event_ids` self is not contained - let chain = self.auth_event_ids(room_id, &ids)?.into_iter().collect::>(); + let chain = self.auth_event_ids(room_id, ids)?.into_iter().collect::>(); auth_chain_sets.push(chain); } diff --git a/crates/ruma-state-res/src/lib.rs b/crates/ruma-state-res/src/lib.rs index 0c0f0bbe..dce57abf 100644 --- a/crates/ruma-state-res/src/lib.rs +++ b/crates/ruma-state-res/src/lib.rs @@ -982,9 +982,7 @@ mod tests { state_sets .iter() .map(|map| { - store - .auth_event_ids(&room_id(), &map.values().cloned().collect::>()) - .unwrap() + store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| ev_map.get(id).map(Arc::clone), @@ -1088,9 +1086,7 @@ mod tests { state_sets .iter() .map(|map| { - store - .auth_event_ids(&room_id(), &map.values().cloned().collect::>()) - .unwrap() + store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| ev_map.get(id).map(Arc::clone), diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index 89a8a07f..5a68cfaf 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -112,9 +112,7 @@ pub fn do_check( state_sets .iter() .map(|map| { - store - .auth_event_ids(&room_id(), &map.values().cloned().collect::>()) - .unwrap() + store.auth_event_ids(&room_id(), map.values().cloned().collect()).unwrap() }) .collect(), |id| event_map.get(id).map(Arc::clone), @@ -217,10 +215,10 @@ impl TestStore { pub fn auth_event_ids( &self, room_id: &RoomId, - event_ids: &[EventId], + event_ids: Vec, ) -> Result> { let mut result = HashSet::new(); - let mut stack = event_ids.to_vec(); + let mut stack = event_ids; // DFS for auth event chain while let Some(ev_id) = stack.pop() {