[pypy-commit] pypy set-strategies: added from_storage_and_strategy function

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:49:35 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49152:1ae8d50ae922
Date: 2011-05-11 18:00 +0200
http://bitbucket.org/pypy/pypy/changeset/1ae8d50ae922/

Log:	added from_storage_and_strategy function

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
@@ -59,6 +59,20 @@
         reprlist = [repr(w_item) for w_item in w_self.getkeys()]
         return "<%s(%s)>" % (w_self.__class__.__name__, ', '.join(reprlist))
 
+    def from_storage_and_strategy(w_self, storage, strategy):
+        objtype = type(w_self)
+        if objtype is W_SetObject:
+            obj = instantiate(W_SetObject)
+        elif objtype is W_FrozensetObject:
+            obj = instantiate(W_FrozensetObject)
+        else:
+            itemiterator = w_self.space.iter(W_SetIterObject(newset(w_self.space)))
+            obj = w_self.space.call_function(w_self.space.type(w_self),itemiterator)
+        obj.space = w_self.space
+        obj.strategy = strategy
+        obj.sstorage = storage
+        return obj
+
     def _newobj(w_self, space, rdict_w=None):
         """Make a new set or frozenset by taking ownership of 'rdict_w'."""
         #return space.call(space.type(w_self),W_SetIterObject(rdict_w))
@@ -197,10 +211,9 @@
     def copy(self, w_set):
         #XXX do not copy FrozenDict
         d = self.cast_from_void_star(w_set.sstorage)
-        #XXX make it faster by using from_storage_and_strategy
-        clone = w_set._newobj(self.space, newset(self.space))
-        clone.strategy = w_set.strategy
-        clone.sstorage = self.cast_to_void_star(d.copy())
+        strategy = w_set.strategy
+        storage = self.cast_to_void_star(d.copy())
+        clone = w_set.from_storage_and_strategy(storage, strategy)
         return clone
 
     def add(self, w_set, w_key):


More information about the pypy-commit mailing list