From ea1878226f6c188ab79feaf9a32e366f62fb5a48 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 26 Jun 2019 01:26:24 +0200 Subject: [PATCH] bpo-37388: Add PyUnicode_Decode(str, 0) fast-path Add a fast-path to PyUnicode_Decode() for size equals to 0. --- Objects/unicodeobject.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b6f3d8f18c4c52c..51d314b61a52c4d 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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); }