Author: Carl Friedrich Bolz <[email protected]>
Branch: 
Changeset: r65452:dee9afbcb403
Date: 2013-07-17 21:45 +0200
http://bitbucket.org/pypy/pypy/changeset/dee9afbcb403/

Log:    somewhat annoying hack: if digits are the default base 10 ones, use
        a specialized recursive function that calls the builtin RPython str
        method. Helps a lot, though.

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -2091,7 +2091,7 @@
 
 _parts_cache = _PartsCache()
 
-def _format_int(val, digits):
+def _format_int_general(val, digits):
     base = len(digits)
     out = []
     while val:
@@ -2100,8 +2100,11 @@
     out.reverse()
     return "".join(out)
 
+def _format_int10(val, digits):
+    return str(val)
 
-def _format_recursive(x, i, output, pts, digits, size_prefix, mindigits):
[email protected](7)
+def _format_recursive(x, i, output, pts, digits, size_prefix, mindigits, 
_format_int):
     # bottomed out with min_digit sized pieces
     # use str of ints
     if i < 0:
@@ -2116,8 +2119,8 @@
             output.append(s)
     else:
         top, bot = x.divmod(pts[i]) # split the number
-        _format_recursive(top, i-1, output, pts, digits, size_prefix, 
mindigits)
-        _format_recursive(bot, i-1, output, pts, digits, size_prefix, 
mindigits)
+        _format_recursive(top, i-1, output, pts, digits, size_prefix, 
mindigits, _format_int)
+        _format_recursive(bot, i-1, output, pts, digits, size_prefix, 
mindigits, _format_int)
 
 def _format(x, digits, prefix='', suffix=''):
     if x.sign == 0:
@@ -2155,7 +2158,14 @@
     if negative:
         output.append('-')
     output.append(prefix)
-    _format_recursive(x, startindex, output, pts, digits, output.getlength(), 
mindigits)
+    if digits == BASE10:
+        _format_recursive(
+            x, startindex, output, pts, digits, output.getlength(), mindigits,
+            _format_int10)
+    else:
+        _format_recursive(
+            x, startindex, output, pts, digits, output.getlength(), mindigits,
+            _format_int_general)
 
     output.append(suffix)
     return output.build()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to