[pypy-commit] pypy py3.6: Optimise the common case for str to int conversion

rlamy pypy.commits at gmail.com
Mon Jun 17 15:04:35 EDT 2019


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.6
Changeset: r96815:102276149584
Date: 2019-06-17 20:03 +0100
http://bitbucket.org/pypy/pypy/changeset/102276149584/

Log:	Optimise the common case for str to int conversion

diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -1882,6 +1882,14 @@
 def unicode_to_decimal_w(space, w_unistr, allow_surrogates=False):
     if not isinstance(w_unistr, W_UnicodeObject):
         raise oefmt(space.w_TypeError, "expected unicode, got '%T'", w_unistr)
+    if w_unistr.is_ascii():
+        # fast path
+        return w_unistr._utf8
+    else:
+        return _unicode_to_decimal_w(space, w_unistr)
+
+def _unicode_to_decimal_w(space, w_unistr):
+    # slow path, in a separate function for the JIT's benefit
     utf8 = w_unistr._utf8
     result = StringBuilder(w_unistr._len())
     it = rutf8.Utf8StringIterator(utf8)


More information about the pypy-commit mailing list