[pypy-commit] pypy default: gah, the rbigint.fromstr factory in the previous form was not at all elidable,

cfbolz noreply at buildbot.pypy.org
Fri Jun 28 14:49:56 CEST 2013


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r65065:5122bb09fd0e
Date: 2013-06-28 14:48 +0200
http://bitbucket.org/pypy/pypy/changeset/5122bb09fd0e/

Log:	gah, the rbigint.fromstr factory in the previous form was not at all
	elidable, due to the extra parser argument. Fix it, by splitting
	things up differently.

diff --git a/pypy/objspace/std/inttype.py b/pypy/objspace/std/inttype.py
--- a/pypy/objspace/std/inttype.py
+++ b/pypy/objspace/std/inttype.py
@@ -10,6 +10,7 @@
 from rpython.rlib.objectmodel import instantiate
 from rpython.rlib.rbigint import rbigint
 from rpython.rlib.rstring import ParseStringError, ParseStringOverflowError
+from rpython.rlib import jit
 
 # ____________________________________________________________
 
@@ -61,6 +62,7 @@
 
 # ____________________________________________________________
 
+ at jit.elidable
 def string_to_int_or_long(space, string, base=10):
     w_longval = None
     value = 0
@@ -73,10 +75,10 @@
         w_longval = retry_to_w_long(space, e.parser)
     return value, w_longval
 
-def retry_to_w_long(space, parser, base=0):
+def retry_to_w_long(space, parser):
     parser.rewind()
     try:
-        bigint = rbigint.fromstr(None, base=base, parser=parser)
+        bigint = rbigint._from_numberstring_parser(parser)
     except ParseStringError, e:
         raise OperationError(space.w_ValueError,
                              space.wrap(e.msg))
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -248,23 +248,26 @@
     @staticmethod
     @jit.elidable
     def fromdecimalstr(s):
-        # This function is marked as pure, so you must not call it and
+        # This function is marked as elidable, so you must not call it and
         # then modify the result.
         return _decimalstr_to_bigint(s)
 
     @staticmethod
     @jit.elidable
-    def fromstr(s, base=0, parser=None):
+    def fromstr(s, base=0):
         """As string_to_int(), but ignores an optional 'l' or 'L' suffix
         and returns an rbigint."""
         from rpython.rlib.rstring import NumberStringParser, \
             strip_spaces
-        if parser is None:
-            s = literal = strip_spaces(s)
-            if (s.endswith('l') or s.endswith('L')) and base < 22:
-                # in base 22 and above, 'L' is a valid digit!  try: long('L',22)
-                s = s[:-1]
-            parser = NumberStringParser(s, literal, base, 'long')
+        s = literal = strip_spaces(s)
+        if (s.endswith('l') or s.endswith('L')) and base < 22:
+            # in base 22 and above, 'L' is a valid digit!  try: long('L',22)
+            s = s[:-1]
+        parser = NumberStringParser(s, literal, base, 'long')
+        return rbigint._from_numberstring_parser(parser)
+
+    @staticmethod
+    def _from_numberstring_parser(parser):
         return parse_digit_string(parser)
 
     @staticmethod
diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -222,6 +222,11 @@
         assert rbigint.fromstr('123L', 21).tolong() == 441 + 42 + 3
         assert rbigint.fromstr('1891234174197319').tolong() == 1891234174197319
 
+    def test_from_numberstring_parser(self):
+        from rpython.rlib.rstring import NumberStringParser
+        parser = NumberStringParser("1231231241", "1231231241", 10, "long")
+        assert rbigint._from_numberstring_parser(parser).tolong() == 1231231241
+
     def test_add(self):
         x = 123456789123456789000000L
         y = 123858582373821923936744221L


More information about the pypy-commit mailing list