[pypy-commit] pypy logging-perf: start playing with unrolling sys._getframe(depth) if depth is constant.

alex_gaynor noreply at buildbot.pypy.org
Tue May 21 19:28:19 CEST 2013


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: logging-perf
Changeset: r64393:4fcf8acb6131
Date: 2013-05-21 10:27 -0700
http://bitbucket.org/pypy/pypy/changeset/4fcf8acb6131/

Log:	start playing with unrolling sys._getframe(depth) if depth is
	constant.

diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -1,14 +1,18 @@
 """
 Implementation of interpreter-level 'sys' routines.
 """
-from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
+
 from rpython.rlib import jit
 from rpython.rlib.runicode import MAXUNICODE
 
+from pypy.interpreter import gateway
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.gateway import unwrap_spec
+
+
 # ____________________________________________________________
 
+
 @unwrap_spec(depth=int)
 def _getframe(space, depth=0):
     """Return a frame object from the call stack.  If optional integer depth is
@@ -21,6 +25,11 @@
     if depth < 0:
         raise OperationError(space.w_ValueError,
                              space.wrap("frame index must not be negative"))
+    return getframe(space, depth)
+
+
+ at jit.look_inside_iff(lambda space, depth: jit.isconstant(depth))
+def getframe(space, depth):
     ec = space.getexecutioncontext()
     f = ec.gettopframe_nohidden()
     while True:
@@ -34,6 +43,7 @@
     f.mark_as_escaped()
     return space.wrap(f)
 
+
 @unwrap_spec(new_limit="c_int")
 def setrecursionlimit(space, new_limit):
     """setrecursionlimit() sets the maximum number of nested calls that


More information about the pypy-commit mailing list