]> granicus.if.org Git - python/commitdiff
Sped intersection by large factors (3-5x faster than before on sets of
authorTim Peters <tim.peters@gmail.com>
Sun, 25 Aug 2002 19:12:45 +0000 (19:12 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 25 Aug 2002 19:12:45 +0000 (19:12 +0000)
cardinality 500; and the smaller the intersection, the bigger the speedup).

Lib/sets.py

index 8808701d24479710c5473a6b4aee618e61c89634..e88e845c1fd35f443896a246597628841dd57cd5 100644 (file)
@@ -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.