Skip to content

Commit

Permalink
Minor XOR optimization
Browse files Browse the repository at this point in the history
The performance benefit is honestly within margin of error, so it might
be better to undo this in favor of the previous simpler implementation.
  • Loading branch information
ToMe25 committed Jun 3, 2024
1 parent c35af22 commit b784e3e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,11 +1659,15 @@ where
/// ```
fn bitxor_assign(&mut self, rhs: &HashSet<T, S>) {
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(), ());
}
};
}
}
}
Expand Down

0 comments on commit b784e3e

Please sign in to comment.