[pypy-commit] pypy kwargsdict-strategy: optimize the keys method

cfbolz noreply at buildbot.pypy.org
Thu Apr 12 15:13:33 CEST 2012


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: kwargsdict-strategy
Changeset: r54306:f37a2d944ce1
Date: 2012-04-12 15:13 +0200
http://bitbucket.org/pypy/pypy/changeset/f37a2d944ce1/

Log:	optimize the keys method

diff --git a/pypy/objspace/std/kwargsdict.py b/pypy/objspace/std/kwargsdict.py
--- a/pypy/objspace/std/kwargsdict.py
+++ b/pypy/objspace/std/kwargsdict.py
@@ -102,8 +102,8 @@
             return w_dict.getitem(w_key)
 
     def w_keys(self, w_dict):
-        l = [self.wrap(key) for key in self.unerase(w_dict.dstorage)[0]]
-        return self.space.newlist(l)
+        l = self.unerase(w_dict.dstorage)[0]
+        return self.space.newlist_str(l[:])
 
     def values(self, w_dict):
         return self.unerase(w_dict.dstorage)[1][:] # to make non-resizable
diff --git a/pypy/objspace/std/test/test_kwargsdict.py b/pypy/objspace/std/test/test_kwargsdict.py
--- a/pypy/objspace/std/test/test_kwargsdict.py
+++ b/pypy/objspace/std/test/test_kwargsdict.py
@@ -76,6 +76,17 @@
     assert d.strategy is not strategy
     assert "StringDictStrategy" == d.strategy.__class__.__name__
 
+def test_keys_doesnt_wrap():
+    space = FakeSpace()
+    space.newlist = None
+    strategy = KwargsDictStrategy(space)
+    keys = ["a", "b", "c"]
+    values = [1, 2, 3]
+    storage = strategy.erase((keys, values))
+    d = W_DictMultiObject(space, strategy, storage)
+    w_l = d.w_keys() # does not crash
+
+
 from pypy.objspace.std.test.test_dictmultiobject import BaseTestRDictImplementation, BaseTestDevolvedDictImplementation
 def get_impl(self):
     storage = strategy.erase(([], []))


More information about the pypy-commit mailing list