Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
reduce branches
  • Loading branch information
kumaraditya303 authored May 2, 2022
commit ca2513ad149700db62faa17c5a084a946d733ea2
18 changes: 9 additions & 9 deletions Include/cpython/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just do it the oldfashioned way?

@kumaraditya303 kumaraditya303 May 2, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done but I wanted to use designated initializer, it looks better

[PyUnicode_2BYTE_KIND] = 0xffffU,
[PyUnicode_4BYTE_KIND] = 0x10ffffU,
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since kind is 3 bits, maybe add extra zero entries for a total of 8?

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))
Expand Down