Skip to content

Commit

Permalink
RangeSet: fix performance regression in difference_update (#346)
Browse files Browse the repository at this point in the history
Optimize RangeSet.difference_update() by avoiding object copy and
also possible costly recursion in case of KeyError in strict mode.

Fixes #346.

Change-Id: Ic35a26ac40e350d8fe8b8108766a0126895b245b
  • Loading branch information
thiell committed Aug 10, 2017
1 parent a2f242c commit 6c75007
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ClusterShell/RangeSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def difference_update(self, other, strict=False):
If strict is True, raise KeyError if an element cannot be removed.
(strict is a RangeSet addition)"""
if strict and other not in self:
raise KeyError(other.difference(self)[0])
raise KeyError(set.difference(other, self).pop())
set.difference_update(self, other)

# Python dict-like mass mutations: update, clear
Expand Down

0 comments on commit 6c75007

Please sign in to comment.