]> granicus.if.org Git - python/commitdiff
bpo-37388: Add PyUnicode_Decode(str, 0) fast-path (GH-14385)
authorVictor Stinner <vstinner@redhat.com>
Tue, 25 Jun 2019 23:49:32 +0000 (01:49 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2019 23:49:32 +0000 (01:49 +0200)
Add a fast-path to PyUnicode_Decode() for size equals to 0.

Objects/unicodeobject.c

index b6f3d8f18c4c52c241d83bfe8eea3be12e303dca..51d314b61a52c4d299b502500ba97be8e5d669e3 100644 (file)
@@ -3354,6 +3354,10 @@ PyUnicode_Decode(const char *s,
         return NULL;
     }
 
+    if (size == 0) {
+        _Py_RETURN_UNICODE_EMPTY();
+    }
+
     if (encoding == NULL) {
         return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
     }