Skip to content

Commit 8620be9

Browse files
authored
bpo-45061: Revert unicode_is_singleton() change (GH-28516)
Don't use a loop over 256 items, only checks for a single singleton.
1 parent 8f943ca commit 8620be9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Objects/unicodeobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,10 @@ unicode_is_singleton(PyObject *unicode)
19941994
if (unicode == state->empty_string) {
19951995
return 1;
19961996
}
1997-
for (Py_ssize_t i = 0; i < 256; i++) {
1998-
if (unicode == state->latin1[i]) {
1997+
PyASCIIObject *ascii = (PyASCIIObject *)unicode;
1998+
if (ascii->state.kind != PyUnicode_WCHAR_KIND && ascii->length == 1) {
1999+
Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0);
2000+
if (ch < 256 && state->latin1[ch] == unicode) {
19992001
return 1;
20002002
}
20012003
}

0 commit comments

Comments
 (0)