diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-08-25 19:12:45 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-08-25 19:12:45 (GMT) |
commit | d33e6be59df8cd8ba701d744ffc2fc7e2d483daa (patch) | |
tree | a4f9cfb1189c3d910567f872110b3081fb07aa62 /Lib/sets.py | |
parent | 4a2f91e302956ecaa5a70c42b403967e4b261a3d (diff) | |
download | cpython-d33e6be59df8cd8ba701d744ffc2fc7e2d483daa.zip cpython-d33e6be59df8cd8ba701d744ffc2fc7e2d483daa.tar.gz cpython-d33e6be59df8cd8ba701d744ffc2fc7e2d483daa.tar.bz2 |
Sped intersection by large factors (3-5x faster than before on sets of
cardinality 500; and the smaller the intersection, the bigger the speedup).
Diffstat (limited to 'Lib/sets.py')
-rw-r--r-- | Lib/sets.py | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/Lib/sets.py b/Lib/sets.py index 8808701..e88e845 100644 --- a/Lib/sets.py +++ b/Lib/sets.py @@ -176,13 +176,8 @@ class BaseSet(object): little, big = self, other else: little, big = other, self - result = self.__class__() - data = result._data - value = True - for elt in little: - if elt in big: - data[elt] = value - return result + common = filter(big._data.has_key, little._data.iterkeys()) + return self.__class__(common) def intersection(self, other): """Return the intersection of two sets as a new set. |