]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fast size check for sub/super set tests
authorRaymond Hettinger <python@rcn.com>
Wed, 21 Aug 2002 02:22:08 +0000 (02:22 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 21 Aug 2002 02:22:08 +0000 (02:22 +0000)
Lib/sets.py

index c678bb449437b83832652d8ab9cd72abc806c579..7b15aa5a012466a57e95a13255bdccb5bc0682d3 100644 (file)
@@ -239,6 +239,8 @@ class BaseSet(object):
     def issubset(self, other):
         """Report whether another set contains this set."""
         self._binary_sanity_check(other)
+        if len(self) > len(other):  # Fast check for obvious cases
+            return False
         for elt in self:
             if elt not in other:
                 return False
@@ -247,6 +249,8 @@ class BaseSet(object):
     def issuperset(self, other):
         """Report whether this set contains another set."""
         self._binary_sanity_check(other)
+        if len(self) < len(other):  # Fast check for obvious cases
+            return False
         for elt in other:
             if elt not in self:
                 return False