Author: Antonio Cuni <[email protected]>
Branch: fastjson
Changeset: r64790:73de5d85c1b3
Date: 2013-06-05 11:32 +0200
http://bitbucket.org/pypy/pypy/changeset/73de5d85c1b3/

Log:    add a fast path for decoding ascii-only, it gives ~10% speedup on
        certain benchmarks

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
@@ -96,13 +96,20 @@
 
     def decode_string(self):
         start = self.i
+        bits = 0
         while not self.eof():
             # this loop is a fast path for strings which do not contain escape
             # characters
             ch = self.next()
+            bits |= ord(ch)
             if ch == '"':
                 content_utf8 = self.getslice(start, self.i-1)
-                content_unicode = unicodehelper.decode_utf8(self.space, 
content_utf8)
+                if bits & 0x80:
+                    # the 8th bit is set, it's an utf8 strnig
+                    content_unicode = content_utf8.decode('utf-8')
+                else:
+                    # ascii only, faster to decode
+                    content_unicode = content_utf8.decode('ascii')
                 self.last_type = TYPE_STRING
                 return self.space.wrap(content_unicode)
             elif ch == '\\':
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to