[pypy-commit] pypy set-strategies: added fastpath for issubset and isdisjoint

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:52:36 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49266:41bcb4199af4
Date: 2011-11-07 12:18 +0100
http://bitbucket.org/pypy/pypy/changeset/41bcb4199af4/

Log:	added fastpath for issubset and isdisjoint

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
@@ -684,6 +684,8 @@
 
         if w_set.strategy is w_other.strategy:
             return self._issubset_unwrapped(w_set, w_other)
+        elif not w_set.strategy.may_contain_equal_elements(w_other.strategy):
+            return False
         else:
             return self._issubset_wrapped(w_set, w_other)
 
@@ -710,6 +712,8 @@
 
         if w_set.strategy is w_other.strategy:
             return self._isdisjoint_unwrapped(w_set, w_other)
+        elif not w_set.strategy.may_contain_equal_elements(w_other.strategy):
+            return True
         else:
             return self._isdisjoint_wrapped(w_set, w_other)
 
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
@@ -615,6 +615,16 @@
         assert a.intersection(b) == set()
         assert b.intersection(a) == set()
 
+        a = set([1,2,3])
+        b = set(["a","b","c"])
+        assert not a.issubset(b)
+        assert not b.issubset(a)
+
+        a = set([1,2,3])
+        b = set(["a","b","c"])
+        assert a.isdisjoint(b)
+        assert b.isdisjoint(a)
+
     def test_empty_intersect(self):
         e = set()
         x = set([1,2,3])


More information about the pypy-commit mailing list