[pypy-commit] pypy stringbuilder3-perf: Optimization for %d.
arigo
noreply at buildbot.pypy.org
Fri Jun 20 19:25:51 CEST 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: stringbuilder3-perf
Changeset: r72108:4284e494350c
Date: 2014-06-20 19:22 +0200
http://bitbucket.org/pypy/pypy/changeset/4284e494350c/
Log: Optimization for %d.
diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py
--- a/pypy/objspace/std/formatting.py
+++ b/pypy/objspace/std/formatting.py
@@ -379,6 +379,19 @@
std_wp._annspecialcase_ = 'specialize:argtype(1)'
def std_wp_number(self, r, prefix=''):
+ result = self.result
+ if len(prefix) == 0 and len(r) >= self.width:
+ # this is strictly a fast path: no prefix, and no padding
+ # needed. It is more efficient code both in the non-jit
+ # case (less testing stuff) and in the jit case (uses only
+ # result.append(), and no startswith() if not f_sign and
+ # not f_blank).
+ if self.f_sign and not r.startswith('-'):
+ result.append(const('+'))
+ elif self.f_blank and not r.startswith('-'):
+ result.append(const(' '))
+ result.append(const(r))
+ return
# add a '+' or ' ' sign if necessary
sign = r.startswith('-')
if not sign:
@@ -391,7 +404,6 @@
# do the padding requested by self.width and the flags,
# without building yet another RPython string but directly
# by pushing the pad character into self.result
- result = self.result
padding = self.width - len(r) - len(prefix)
if padding <= 0:
padding = 0
More information about the pypy-commit
mailing list