[pypy-commit] pypy default: Issue #1867 -- fixed performance and memory issues with operator.methodcaller

alex_gaynor noreply at buildbot.pypy.org
Tue Sep 16 20:33:28 CEST 2014


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r73558:c7fcbd1bcedd
Date: 2014-09-16 11:32 -0700
http://bitbucket.org/pypy/pypy/changeset/c7fcbd1bcedd/

Log:	Issue #1867 -- fixed performance and memory issues with
	operator.methodcaller

diff --git a/pypy/module/operator/app_operator.py b/pypy/module/operator/app_operator.py
--- a/pypy/module/operator/app_operator.py
+++ b/pypy/module/operator/app_operator.py
@@ -120,7 +120,11 @@
     return builtinify(getter)
 
 
-def methodcaller(method_name, *args, **kwargs):
-    def call(obj):
-        return getattr(obj, method_name)(*args, **kwargs)
-    return builtinify(call)
+class methodcaller(object):
+    def __init__(self, method_name, *args, **kwargs):
+        self._method_name = method_name
+        self._args = args
+        self._kwargs = kwargs
+
+    def __call__(self, obj):
+        return getattr(obj, self._method_name)(*self._args, **self._kwargs)


More information about the pypy-commit mailing list