[pypy-svn] r48892 - pypy/dist/pypy/objspace/std
xoraxax at codespeak.net
xoraxax at codespeak.net
Wed Nov 21 12:04:40 CET 2007
Author: xoraxax
Date: Wed Nov 21 12:04:39 2007
New Revision: 48892
Modified:
pypy/dist/pypy/objspace/std/dictmultiobject.py
pypy/dist/pypy/objspace/std/dicttype.py
Log:
Add a dict.pop MM for the dictmultiobject to avoid using the slow app-level version from dicttype.
Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictmultiobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictmultiobject.py Wed Nov 21 12:04:39 2007
@@ -1235,6 +1235,21 @@
def dict_get__DictMulti_ANY_ANY(space, w_dict, w_lookup, w_default):
return w_dict.get(w_lookup, w_default)
+def dict_pop__DictMulti_ANY(space, w_dict, w_key, w_defaults):
+ defaults = space.unpackiterable(w_defaults)
+ len_defaults = len(defaults)
+ if len_defaults > 1:
+ raise OperationError(space.w_TypeError, space.wrap("pop expected at most 2 arguments, got %d" % (1 + len_defaults, )))
+ w_item = w_dict.implementation.get(w_key)
+ if w_item is None:
+ if len_defaults > 0:
+ return defaults[0]
+ else:
+ raise OperationError(space.w_KeyError, w_key)
+ else:
+ w_dict.implementation.delitem(w_key)
+ return w_item
+
app = gateway.applevel('''
def dictrepr(currently_in_repr, d):
# Now we only handle one implementation of dicts, this one.
Modified: pypy/dist/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dicttype.py (original)
+++ pypy/dist/pypy/objspace/std/dicttype.py Wed Nov 21 12:04:39 2007
@@ -52,6 +52,8 @@
#dict_str = StdObjSpace.str
# default application-level implementations for some operations
+# most of these (notably not popitem and update*) are overwritten
+# in dictmultiobject
# gateway is imported in the stdtypedef module
app = gateway.applevel('''
@@ -64,9 +66,10 @@
d[k] = v
def update(d, *args, **kwargs):
- if len(args) == 1:
+ len_args = len(args)
+ if len_args == 1:
update1(d, args[0])
- elif len(args) > 1:
+ elif len_args > 1:
raise TypeError("update takes at most 1 (non-keyword) argument")
if kwargs:
update1(d, kwargs)
More information about the Pypy-commit
mailing list