[pypy-commit] pypy set-strategies: refactored issuperset (no wrapping when strategies are equal)

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:51:20 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49207:80d1c500bc62
Date: 2011-10-10 13:32 +0200
http://bitbucket.org/pypy/pypy/changeset/80d1c500bc62/

Log:	refactored issuperset (no wrapping when strategies are equal)

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
@@ -421,13 +421,13 @@
         return storage, strategy
 
     def difference(self, w_set, w_other):
-        #XXX return clone in certain cases: String- with IntStrategy or ANY with Empty
+        #XXX return clone for ANY with Empty (and later different strategies)
         storage, strategy = self._difference_base(w_set, w_other)
         w_newset = w_set.from_storage_and_strategy(storage, strategy)
         return w_newset
 
     def difference_update(self, w_set, w_other):
-        #XXX do nothing in certain cases: String- with IntStrategy or ANY with Empty
+        #XXX do nothing for ANY with Empty
         storage, strategy = self._difference_base(w_set, w_other)
         w_set.strategy = strategy
         w_set.sstorage = storage
@@ -540,10 +540,16 @@
         w_set.strategy = result.strategy
         w_set.sstorage = result.sstorage
 
-    def issuperset(self, w_set, w_other):
-        if w_other.length() == 0:
-            return True
+    def _issuperset_unwrapped(self, w_set, w_other):
+        d_set = self.cast_from_void_star(w_set.sstorage)
+        d_other = self.cast_from_void_star(w_other.sstorage)
 
+        for e in d_other.keys():
+            if not e in d_set:
+                return False
+        return True
+
+    def _issuperset_wrapped(self, w_set, w_other):
         w_iter = self.space.iter(w_other)
         while True:
             try:
@@ -556,6 +562,15 @@
                 return True
         return True
 
+    def issuperset(self, w_set, w_other):
+        if w_other.length() == 0:
+            return True
+
+        if w_set.strategy is w_other.strategy:
+            return self._issuperset_unwrapped(w_set, w_other)
+        else:
+            return self._issuperset_wrapped(w_set, w_other)
+
     def isdisjoint(self, w_set, w_other):
         if w_other.length() == 0:
             return True


More information about the pypy-commit mailing list