Skip to content

Commit fcb964b

Browse files
committed
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.
1 parent 28982b9 commit fcb964b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/set.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,11 +1659,15 @@ where
16591659
/// ```
16601660
fn bitxor_assign(&mut self, rhs: &HashSet<T, S>) {
16611661
for item in rhs {
1662-
if self.contains(item) {
1663-
self.remove(item);
1664-
} else {
1665-
self.insert(item.clone());
1666-
}
1662+
let entry = self.map.raw_entry_mut().from_key(item);
1663+
match entry {
1664+
map::RawEntryMut::Occupied(e) => {
1665+
e.remove();
1666+
}
1667+
map::RawEntryMut::Vacant(e) => {
1668+
e.insert(item.to_owned(), ());
1669+
}
1670+
};
16671671
}
16681672
}
16691673
}

0 commit comments

Comments
 (0)