diff options
author | Raymond Hettinger <python@rcn.com> | 2002-08-21 02:22:08 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-08-21 02:22:08 (GMT) |
commit | 43db0d6a2c5d57c9cd713928f73b993add965b82 (patch) | |
tree | d60d14f69940b35dc478a720e875655e5423834c /Lib/sets.py | |
parent | de6d6979873b9e7d8066463dff8af4cc65e14e31 (diff) | |
download | cpython-43db0d6a2c5d57c9cd713928f73b993add965b82.zip cpython-43db0d6a2c5d57c9cd713928f73b993add965b82.tar.gz cpython-43db0d6a2c5d57c9cd713928f73b993add965b82.tar.bz2 |
Fast size check for sub/super set tests
Diffstat (limited to 'Lib/sets.py')
-rw-r--r-- | Lib/sets.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/sets.py b/Lib/sets.py index c678bb4..7b15aa5 100644 --- a/Lib/sets.py +++ b/Lib/sets.py @@ -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 |