Skip to content

Commit ca2513a

Browse files
reduce branches
1 parent 6811bde commit ca2513a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Include/cpython/unicodeobject.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,17 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
436436
if (PyUnicode_IS_ASCII(op)) {
437437
return 0x7fU;
438438
}
439-
439+
static const Py_UCS4 max_char_values[] = {
440+
[PyUnicode_1BYTE_KIND] = 0xffU,
441+
[PyUnicode_2BYTE_KIND] = 0xffffU,
442+
[PyUnicode_4BYTE_KIND] = 0x10ffffU,
443+
};
440444
unsigned int kind = PyUnicode_KIND(op);
441-
if (kind == PyUnicode_1BYTE_KIND) {
442-
return 0xffU;
443-
}
444-
if (kind == PyUnicode_2BYTE_KIND) {
445-
return 0xffffU;
446-
}
447-
assert(kind == PyUnicode_4BYTE_KIND);
448-
return 0x10ffffU;
445+
const Py_UCS4 value = max_char_values[kind];
446+
assert(value);
447+
return value;
449448
}
449+
450450
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
451451
# define PyUnicode_MAX_CHAR_VALUE(op) \
452452
PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op))

0 commit comments

Comments
 (0)