[pypy-commit] pypy set-strategies: (cfbolz, l.diekmann) added fastpath for dict.fromkeys with iterable using stringstrategy
l.diekmann
noreply at buildbot.pypy.org
Wed Jan 11 14:24:41 CET 2012
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r51222:b8be45d7d460
Date: 2012-01-11 14:24 +0100
http://bitbucket.org/pypy/pypy/changeset/b8be45d7d460/
Log: (cfbolz, l.diekmann) added fastpath for dict.fromkeys with iterable
using stringstrategy
diff --git a/pypy/objspace/std/dicttype.py b/pypy/objspace/std/dicttype.py
--- a/pypy/objspace/std/dicttype.py
+++ b/pypy/objspace/std/dicttype.py
@@ -62,8 +62,14 @@
w_fill = space.w_None
if space.is_w(w_type, space.w_dict):
w_dict = W_DictMultiObject.allocate_and_init_instance(space, w_type)
- for w_key in space.listview(w_keys):
- w_dict.setitem(w_key, w_fill)
+
+ strlist = space.listview_str(w_keys)
+ if strlist is not None:
+ for key in strlist:
+ w_dict.setitem_str(key, w_fill)
+ else:
+ for w_key in space.listview(w_keys):
+ w_dict.setitem(w_key, w_fill)
else:
w_dict = space.call_function(w_type)
for w_key in space.listview(w_keys):
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -131,6 +131,16 @@
assert self.space.eq_w(space.call_function(get, w("33")), w(None))
assert self.space.eq_w(space.call_function(get, w("33"), w(44)), w(44))
+ def test_fromkeys_fastpath(self):
+ space = self.space
+ w = space.wrap
+
+ w_l = self.space.newlist([w("a"),w("b")])
+ w_l.getitems = None
+ w_d = space.call_method(space.w_dict, "fromkeys", w_l)
+
+ assert space.eq_w(w_d.getitem_str("a"), space.w_None)
+ assert space.eq_w(w_d.getitem_str("b"), space.w_None)
class AppTest_DictObject:
def setup_class(cls):
More information about the pypy-commit
mailing list