From ca2513ad149700db62faa17c5a084a946d733ea2 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 2 May 2022 14:21:20 +0000 Subject: [PATCH 1/3] reduce branches --- Include/cpython/unicodeobject.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 0397f12a8260b06..ce9b881cdd7ff17 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -436,17 +436,17 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op) if (PyUnicode_IS_ASCII(op)) { return 0x7fU; } - + static const Py_UCS4 max_char_values[] = { + [PyUnicode_1BYTE_KIND] = 0xffU, + [PyUnicode_2BYTE_KIND] = 0xffffU, + [PyUnicode_4BYTE_KIND] = 0x10ffffU, + }; unsigned int kind = PyUnicode_KIND(op); - if (kind == PyUnicode_1BYTE_KIND) { - return 0xffU; - } - if (kind == PyUnicode_2BYTE_KIND) { - return 0xffffU; - } - assert(kind == PyUnicode_4BYTE_KIND); - return 0x10ffffU; + const Py_UCS4 value = max_char_values[kind]; + assert(value); + return value; } + #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 # define PyUnicode_MAX_CHAR_VALUE(op) \ PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op)) From fa06bb033b57da62136e2ba79be02e86a2852633 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 2 May 2022 16:07:49 +0000 Subject: [PATCH 2/3] old style --- Include/cpython/unicodeobject.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index ce9b881cdd7ff17..6991c45162dd131 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -436,10 +436,12 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op) if (PyUnicode_IS_ASCII(op)) { return 0x7fU; } - static const Py_UCS4 max_char_values[] = { - [PyUnicode_1BYTE_KIND] = 0xffU, - [PyUnicode_2BYTE_KIND] = 0xffffU, - [PyUnicode_4BYTE_KIND] = 0x10ffffU, + static Py_UCS4 max_char_values[] = { + 0, /* PyUnicode_WCHAR_KIND */ + 0xffU, /* PyUnicode_1BYTE_KIND */ + 0xffffU, /* PyUnicode_2BYTE_KIND */ + 0, + 0x10ffffU, /* PyUnicode_4BYTE_KIND */ }; unsigned int kind = PyUnicode_KIND(op); const Py_UCS4 value = max_char_values[kind]; From 2782355556b5c8182728ed6d77f9dbcc4aace653 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 2 May 2022 16:09:06 +0000 Subject: [PATCH 3/3] const --- Include/cpython/unicodeobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 6991c45162dd131..a07034e6e95088d 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -436,7 +436,7 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op) if (PyUnicode_IS_ASCII(op)) { return 0x7fU; } - static Py_UCS4 max_char_values[] = { + static const Py_UCS4 max_char_values[] = { 0, /* PyUnicode_WCHAR_KIND */ 0xffU, /* PyUnicode_1BYTE_KIND */ 0xffffU, /* PyUnicode_2BYTE_KIND */