Issue #28701: Replace _PyUnicode_CompareWithId with _PyUnicode_EqualToASCIIId.

The latter function is more readable, faster and doesn't raise exceptions.

Based on patch by Xiang Zhang.
This commit is contained in:
Serhiy Storchaka 2016-11-16 15:41:11 +02:00
commit fab6acd9f5
5 changed files with 65 additions and 8 deletions

View file

@ -2037,12 +2037,31 @@ PyAPI_FUNC(int) PyUnicode_Compare(
);
#ifndef Py_LIMITED_API
/* Compare a string with an identifier and return -1, 0, 1 for less than,
equal, and greater than, respectively.
Raise an exception and return -1 on error. */
PyAPI_FUNC(int) _PyUnicode_CompareWithId(
PyObject *left, /* Left string */
_Py_Identifier *right /* Right identifier */
);
/* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
0 otherwise. Return 0 if any argument contains non-ASCII characters.
Any error occurs inside will be cleared before return. */
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
PyObject *left, /* Left string */
_Py_Identifier *right /* Right identifier */
);
#endif
/* Compare a Unicode object with C string and return -1, 0, 1 for less than,
equal, and greater than, respectively. It is best to pass only
ASCII-encoded strings, but the function interprets the input string as
ISO-8859-1 if it contains non-ASCII characters.
Raise an exception and return -1 on error. */
PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString(
PyObject *left,
const char *right /* ASCII-encoded string */