Commit 60b00913 authored by Raymond Hettinger's avatar Raymond Hettinger

Fast size check for sub/super set tests

parent 36b90451
...@@ -239,6 +239,8 @@ class BaseSet(object): ...@@ -239,6 +239,8 @@ class BaseSet(object):
def issubset(self, other): def issubset(self, other):
"""Report whether another set contains this set.""" """Report whether another set contains this set."""
self._binary_sanity_check(other) self._binary_sanity_check(other)
if len(self) > len(other): # Fast check for obvious cases
return False
for elt in self: for elt in self:
if elt not in other: if elt not in other:
return False return False
...@@ -247,6 +249,8 @@ class BaseSet(object): ...@@ -247,6 +249,8 @@ class BaseSet(object):
def issuperset(self, other): def issuperset(self, other):
"""Report whether this set contains another set.""" """Report whether this set contains another set."""
self._binary_sanity_check(other) self._binary_sanity_check(other)
if len(self) < len(other): # Fast check for obvious cases
return False
for elt in other: for elt in other:
if elt not in self: if elt not in self:
return False return False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment