From b784e3e91e4cca481f1d0c247a126fe533cabe93 Mon Sep 17 00:00:00 2001 From: ToMe25 Date: Mon, 3 Jun 2024 19:29:16 +0200 Subject: [PATCH] Minor XOR optimization The performance benefit is honestly within margin of error, so it might be better to undo this in favor of the previous simpler implementation. --- src/set.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/set.rs b/src/set.rs index 2c9e7f22c..a1254cba6 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1659,11 +1659,15 @@ where /// ``` fn bitxor_assign(&mut self, rhs: &HashSet) { for item in rhs { - if self.contains(item) { - self.remove(item); - } else { - self.insert(item.clone()); - } + let entry = self.map.raw_entry_mut().from_key(item); + match entry { + map::RawEntryMut::Occupied(e) => { + e.remove(); + } + map::RawEntryMut::Vacant(e) => { + e.insert(item.to_owned(), ()); + } + }; } } }