Author: Philip Jenvey <pjen...@underboss.org>
Branch: 
Changeset: r64954:d0acdb6e6b8a
Date: 2013-06-21 12:31 -0700
http://bitbucket.org/pypy/pypy/changeset/d0acdb6e6b8a/

Log:    merge upstream

diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -1062,14 +1062,22 @@
 
     def _intersect_base(self, w_set, w_other):
         if self is w_other.strategy:
-            strategy = w_set.strategy
-            storage = strategy._intersect_unwrapped(w_set, w_other)
+            strategy = self
+            if w_set.length() > w_other.length():
+                # swap operants
+                storage = self._intersect_unwrapped(w_other, w_set)
+            else:
+                storage = self._intersect_unwrapped(w_set, w_other)
         elif not w_set.strategy.may_contain_equal_elements(w_other.strategy):
             strategy = self.space.fromcache(EmptySetStrategy)
             storage = strategy.get_empty_storage()
         else:
             strategy = self.space.fromcache(ObjectSetStrategy)
-            storage = self._intersect_wrapped(w_set, w_other)
+            if w_set.length() > w_other.length():
+                # swap operants
+                storage = w_other.strategy._intersect_wrapped(w_other, w_set)
+            else:
+                storage = self._intersect_wrapped(w_set, w_other)
         return storage, strategy
 
     def _intersect_wrapped(self, w_set, w_other):
@@ -1092,9 +1100,6 @@
         return self.erase(result)
 
     def intersect(self, w_set, w_other):
-        if w_set.length() > w_other.length():
-            return w_other.intersect(w_set)
-
         storage, strategy = self._intersect_base(w_set, w_other)
         return w_set.from_storage_and_strategy(storage, strategy)
 
diff --git a/pypy/objspace/std/test/test_setobject.py 
b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -953,3 +953,10 @@
         # getting a RuntimeError because iterating over the old storage
         # gives us 1, but 1 is not in the set any longer.
         raises(RuntimeError, list, it)
+
+    def test_intersect_frozenset_set(self):
+        # worked before
+        assert type(frozenset([2]) & set([1, 2])) is frozenset
+        # did not work before because of an optimization that swaps both
+        # operands when the first set is larger than the second
+        assert type(frozenset([1, 2]) & set([2])) is frozenset
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to