Commits

Lukas Diekmann committed fca421c

added fastpath to intersection and fixed not_contain_equal_elements

Comments (0)

Files changed (2)

pypy/objspace/std/setobject.py

         if self is w_other.strategy:
             strategy = w_set.strategy
             storage = strategy._intersect_unwrapped(w_set, w_other)
+        elif not_contain_equal_elements(self.space, w_set, w_other):
+            strategy = self.space.fromcache(EmptySetStrategy)
+            storage = strategy.get_empty_storage()
         else:
             strategy = self.space.fromcache(ObjectSetStrategy)
             storage = self._intersect_wrapped(w_set, w_other)
 # some helper functions
 
 def not_contain_equal_elements(space, w_set, w_other):
+    # add strategies here for which elements from sets with theses strategies are never equal.
+
     strategy1 = w_set.strategy
     strategy2 = w_other.strategy
-    # add strategies here for which elements from sets with theses strategies are never equal.
+
     if strategy1 is space.fromcache(StringSetStrategy) and strategy2 is space.fromcache(IntegerSetStrategy):
         return True
+    if strategy1 is space.fromcache(IntegerSetStrategy) and strategy2 is space.fromcache(StringSetStrategy):
+        return True
+
     if strategy1 is space.fromcache(EmptySetStrategy) or strategy2 is space.fromcache(EmptySetStrategy):
         # an empty set and another set will never have any equal element
         return True

pypy/objspace/std/test/test_setobject.py

         x.symmetric_difference_update(set())
         assert x == set([1,2,3])
 
-    def test_difference_uncomparable_strategies(self):
+    def test_fastpath_with_strategies(self):
         a = set([1,2,3])
         b = set(["a","b","c"])
         assert a.difference(b) == a
         assert b.difference(a) == b
 
+        a = set([1,2,3])
+        b = set(["a","b","c"])
+        assert a.intersection(b) == set()
+        assert b.intersection(a) == set()
+
     def test_empty_intersect(self):
         e = set()
         x = set([1,2,3])