Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.6
Changeset: r97743:40f56f2802c9
Date: 2019-10-09 12:21 +0200
http://bitbucket.org/pypy/pypy/changeset/40f56f2802c9/

Log:    move fast path from interp_codecs to unicodehelper, since several
        places call that directly

diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -375,6 +375,14 @@
         return res_utf8, len(res), size
 
 def str_decode_utf8(s, errors, final, errorhandler, allow_surrogates=False):
+    try:
+        # fast version first
+        return s, rutf8.check_utf8(s, allow_surrogates=allow_surrogates), 
len(s)
+    except rutf8.CheckError:
+        return _str_decode_utf8_slowpath(
+            s, errors, final, errorhandler, allow_surrogates=allow_surrogates)
+
+def _str_decode_utf8_slowpath(s, errors, final, errorhandler, 
allow_surrogates):
     """ Same as checking for the valid utf8, but we know the utf8 is not
     valid so we're trying to either raise or pack stuff with error handler.
     The key difference is that this is call_may_force
diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -737,17 +737,10 @@
         errors = 'strict'
     final = space.is_true(w_final)
     state = space.fromcache(CodecState)
-    # call the fast version for checking
-    try:
-        lgt = rutf8.check_utf8(string, allow_surrogates=False)
-    except rutf8.CheckError:
-        res, lgt, pos = unicodehelper.str_decode_utf8(string,
-            errors, final, state.decode_error_handler)
-        return space.newtuple([space.newutf8(res, lgt),
-                               space.newint(pos)])
-    else:
-        return space.newtuple([space.newutf8(string, lgt),
-                               space.newint(len(string))])
+    res, lgt, pos = unicodehelper.str_decode_utf8(string,
+        errors, final, state.decode_error_handler)
+    return space.newtuple([space.newutf8(res, lgt),
+                           space.newint(pos)])
 
 @unwrap_spec(data='bufferstr', errors='text_or_none', byteorder=int,
              w_final=WrappedDefault(False))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to