Skip to content

Commit 156f94d

Browse files
committed
⚡ Make SequenceSet#xor ~1.4x faster
The results are highly dependant on data, YJIT, etc... but in my tests this implementation seems to _consistently_ run more than 1.3x faster. ``` current (L - R) | (R - L): 905.0 i/s 0.5.8 (L | R) - (R & L): 624.1 i/s - 1.45x slower ```
1 parent e9ef2c4 commit 156f94d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/net/imap/sequence_set.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,8 +1475,9 @@ def intersect!(other) # :nodoc:
14751475
# TODO: document and directly test this
14761476
def xor!(other) # :nodoc:
14771477
modifying!
1478-
both = self & other
1479-
merge(other).subtract(both)
1478+
copy = dup
1479+
other = SequenceSet.new(other)
1480+
merge(other).subtract(other.subtract(copy.complement!))
14801481
end
14811482

14821483
# Returns a new SequenceSet with a normalized string representation.

0 commit comments

Comments
 (0)