[pypy-commit] pypy unroll-if-alt: allow _build_string to be unrolled if the template is constant
gutworth
noreply at buildbot.pypy.org
Sat Jul 30 23:31:16 CEST 2011
Author: Benjamin Peterson <benjamin at python.org>
Branch: unroll-if-alt
Changeset: r46113:f45b04b331a6
Date: 2011-07-30 16:31 -0500
http://bitbucket.org/pypy/pypy/changeset/f45b04b331a6/
Log: allow _build_string to be unrolled if the template is constant
diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -3,7 +3,8 @@
import string
from pypy.interpreter.error import OperationError
-from pypy.rlib import rstring, runicode, rlocale, rarithmetic, rfloat
+from pypy.tool import sourcetools
+from pypy.rlib import rstring, runicode, rlocale, rarithmetic, rfloat, jit
from pypy.rlib.objectmodel import specialize
from pypy.rlib.rfloat import copysign, formatd
@@ -65,6 +66,13 @@
space.wrap("Recursion depth exceeded"))
level -= 1
s = self.template
+ if jit.isconstant(s):
+ return self._do_build_string_unroll(start, end, level, out, s)
+ else:
+ return self._do_build_string(start, end, level, out, s)
+
+ def _do_build_string(self, start, end, level, out, s):
+ space = self.space
last_literal = i = start
while i < end:
c = s[i]
@@ -115,6 +123,11 @@
out.append_slice(s, last_literal, end)
return out.build()
+ f = sourcetools.func_with_new_name(_do_build_string,
+ "_do_build_string_unroll")
+ _do_build_string_unroll = jit.unroll_safe(f)
+ del f
+
def _parse_field(self, start, end):
s = self.template
# Find ":" or "!"
More information about the pypy-commit
mailing list