Author: Carl Friedrich Bolz <[email protected]>
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(([], []))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit