[pypy-commit] pypy fastjson: speed up parse_digits by storing self.i only at the end

antocuni noreply at buildbot.pypy.org
Sun Jun 9 11:41:48 CEST 2013


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fastjson
Changeset: r64829:16e72115b986
Date: 2013-06-06 16:28 +0200
http://bitbucket.org/pypy/pypy/changeset/16e72115b986/

Log:	speed up parse_digits by storing self.i only at the end

diff --git a/pypy/module/_fastjson/interp_decoder.py b/pypy/module/_fastjson/interp_decoder.py
--- a/pypy/module/_fastjson/interp_decoder.py
+++ b/pypy/module/_fastjson/interp_decoder.py
@@ -178,16 +178,18 @@
         "Parse a sequence of digits as a decimal number. No sign allowed"
         intval = 0
         count = 0
-        while not self.eof():
-            ch = self.peek()
+        i = self.i
+        while i < len(self.s):
+            ch = self.s[i]
             if ch.isdigit():
                 intval = intval*10 + ord(ch)-ord('0')
                 count += 1
-                self.next()
+                i += 1
             else:
                 break
         if count == 0:
-            self._raise("Expected digit at char %d", self.i)
+            self._raise("Expected digit at char %d", i)
+        self.i = i
         return intval, count
         
     def decode_array(self):
@@ -252,8 +254,6 @@
                             ch, self.i)
         self._raise("Unterminated object starting at char %d", start)
 
-
-
     def decode_string(self):
         start = self.i
         i = self.i


More information about the pypy-commit mailing list