[pypy-commit] pypy py3.5: put common case first, exit quickly on empty byte string

mattip pypy.commits at gmail.com
Sun Nov 18 03:57:44 EST 2018


Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.5
Changeset: r95331:0d38f5b5e3e5
Date: 2018-11-18 00:55 -0800
http://bitbucket.org/pypy/pypy/changeset/0d38f5b5e3e5/

Log:	put common case first, exit quickly on empty byte string

diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -530,11 +530,16 @@
 
     All other objects, including Unicode objects, cause a TypeError to be
     set."""
-    if space.isinstance_w(w_obj, space.w_unicode):
+    if space.isinstance_w(w_obj, space.w_bytes):
+        s = space.bytes_w(w_obj)
+        if not s:
+            return space.newtext('', 0)
+    elif space.isinstance_w(w_obj, space.w_unicode):
         raise oefmt(space.w_TypeError, "decoding str is not supported")
-    if space.isinstance_w(w_obj, space.w_bytearray):   # Python 2.x specific
+    elif space.isinstance_w(w_obj, space.w_bytearray):   # Python 2.x specific
         raise oefmt(space.w_TypeError, "decoding bytearray is not supported")
-    s = space.charbuf_w(w_obj)
+    else:
+        s = space.buffer_w(w_obj, 0)
     return _pyunicode_decode(space, s, encoding, errors)
 
 


More information about the pypy-commit mailing list