mirror of https://github.com/python/cpython
gh-124502: Remove _PyUnicode_EQ() function (#125114)
* Replace unicode_compare_eq() with unicode_eq(). * Use unicode_eq() in setobject.c. * Replace _PyUnicode_EQ() with _PyUnicode_Equal(). * Remove unicode_compare_eq() and _PyUnicode_EQ().
This commit is contained in:
parent
7f93dbf6fe
commit
e0c87c64b1
|
@ -252,11 +252,7 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping(
|
||||||
|
|
||||||
extern PyObject* _PyUnicode_FormatLong(PyObject *, int, int, int);
|
extern PyObject* _PyUnicode_FormatLong(PyObject *, int, int, int);
|
||||||
|
|
||||||
/* Fast equality check when the inputs are known to be exact unicode types
|
// Fast equality check when the inputs are known to be exact unicode types.
|
||||||
and where the hash values are equal (i.e. a very probable match) */
|
|
||||||
extern int _PyUnicode_EQ(PyObject *, PyObject *);
|
|
||||||
|
|
||||||
// Equality check.
|
|
||||||
// Export for '_pickle' shared extension.
|
// Export for '_pickle' shared extension.
|
||||||
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *, PyObject *);
|
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *, PyObject *);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_SSIZE_RELAXED()
|
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_SSIZE_RELAXED()
|
||||||
#include "pycore_pyerrors.h" // _PyErr_SetKeyError()
|
#include "pycore_pyerrors.h" // _PyErr_SetKeyError()
|
||||||
#include "pycore_setobject.h" // _PySet_NextEntry() definition
|
#include "pycore_setobject.h" // _PySet_NextEntry() definition
|
||||||
|
|
||||||
|
#include "stringlib/eq.h" // unicode_eq()
|
||||||
#include <stddef.h> // offsetof()
|
#include <stddef.h> // offsetof()
|
||||||
#include "clinic/setobject.c.h"
|
#include "clinic/setobject.c.h"
|
||||||
|
|
||||||
|
@ -96,7 +98,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
return entry;
|
return entry;
|
||||||
if (PyUnicode_CheckExact(startkey)
|
if (PyUnicode_CheckExact(startkey)
|
||||||
&& PyUnicode_CheckExact(key)
|
&& PyUnicode_CheckExact(key)
|
||||||
&& _PyUnicode_EQ(startkey, key))
|
&& unicode_eq(startkey, key))
|
||||||
return entry;
|
return entry;
|
||||||
table = so->table;
|
table = so->table;
|
||||||
Py_INCREF(startkey);
|
Py_INCREF(startkey);
|
||||||
|
@ -157,7 +159,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
goto found_active;
|
goto found_active;
|
||||||
if (PyUnicode_CheckExact(startkey)
|
if (PyUnicode_CheckExact(startkey)
|
||||||
&& PyUnicode_CheckExact(key)
|
&& PyUnicode_CheckExact(key)
|
||||||
&& _PyUnicode_EQ(startkey, key))
|
&& unicode_eq(startkey, key))
|
||||||
goto found_active;
|
goto found_active;
|
||||||
table = so->table;
|
table = so->table;
|
||||||
Py_INCREF(startkey);
|
Py_INCREF(startkey);
|
||||||
|
|
|
@ -261,7 +261,6 @@ _PyUnicode_InternedSize_Immortal(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Py_hash_t unicode_hash(PyObject *);
|
static Py_hash_t unicode_hash(PyObject *);
|
||||||
static int unicode_compare_eq(PyObject *, PyObject *);
|
|
||||||
|
|
||||||
static Py_uhash_t
|
static Py_uhash_t
|
||||||
hashtable_unicode_hash(const void *key)
|
hashtable_unicode_hash(const void *key)
|
||||||
|
@ -275,7 +274,7 @@ hashtable_unicode_compare(const void *key1, const void *key2)
|
||||||
PyObject *obj1 = (PyObject *)key1;
|
PyObject *obj1 = (PyObject *)key1;
|
||||||
PyObject *obj2 = (PyObject *)key2;
|
PyObject *obj2 = (PyObject *)key2;
|
||||||
if (obj1 != NULL && obj2 != NULL) {
|
if (obj1 != NULL && obj2 != NULL) {
|
||||||
return unicode_compare_eq(obj1, obj2);
|
return unicode_eq(obj1, obj2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return obj1 == obj2;
|
return obj1 == obj2;
|
||||||
|
@ -10968,26 +10967,6 @@ unicode_compare(PyObject *str1, PyObject *str2)
|
||||||
#undef COMPARE
|
#undef COMPARE
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
unicode_compare_eq(PyObject *str1, PyObject *str2)
|
|
||||||
{
|
|
||||||
int kind;
|
|
||||||
const void *data1, *data2;
|
|
||||||
Py_ssize_t len;
|
|
||||||
int cmp;
|
|
||||||
|
|
||||||
len = PyUnicode_GET_LENGTH(str1);
|
|
||||||
if (PyUnicode_GET_LENGTH(str2) != len)
|
|
||||||
return 0;
|
|
||||||
kind = PyUnicode_KIND(str1);
|
|
||||||
if (PyUnicode_KIND(str2) != kind)
|
|
||||||
return 0;
|
|
||||||
data1 = PyUnicode_DATA(str1);
|
|
||||||
data2 = PyUnicode_DATA(str2);
|
|
||||||
|
|
||||||
cmp = memcmp(data1, data2, len * kind);
|
|
||||||
return (cmp == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
_PyUnicode_Equal(PyObject *str1, PyObject *str2)
|
_PyUnicode_Equal(PyObject *str1, PyObject *str2)
|
||||||
|
@ -10997,7 +10976,7 @@ _PyUnicode_Equal(PyObject *str1, PyObject *str2)
|
||||||
if (str1 == str2) {
|
if (str1 == str2) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return unicode_compare_eq(str1, str2);
|
return unicode_eq(str1, str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11213,7 +11192,7 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return unicode_compare_eq(left, right_uni);
|
return unicode_eq(left, right_uni);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
@ -11241,7 +11220,7 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (op == Py_EQ || op == Py_NE) {
|
else if (op == Py_EQ || op == Py_NE) {
|
||||||
result = unicode_compare_eq(left, right);
|
result = unicode_eq(left, right);
|
||||||
result ^= (op == Py_NE);
|
result ^= (op == Py_NE);
|
||||||
return PyBool_FromLong(result);
|
return PyBool_FromLong(result);
|
||||||
}
|
}
|
||||||
|
@ -11251,12 +11230,6 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
_PyUnicode_EQ(PyObject *aa, PyObject *bb)
|
|
||||||
{
|
|
||||||
return unicode_eq(aa, bb);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
PyUnicode_Contains(PyObject *str, PyObject *substr)
|
PyUnicode_Contains(PyObject *str, PyObject *substr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2064,7 +2064,7 @@ find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
|
||||||
for (i = 0; i < nkwargs; i++) {
|
for (i = 0; i < nkwargs; i++) {
|
||||||
PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
|
PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
|
||||||
assert(PyUnicode_Check(kwname));
|
assert(PyUnicode_Check(kwname));
|
||||||
if (_PyUnicode_EQ(kwname, key)) {
|
if (_PyUnicode_Equal(kwname, key)) {
|
||||||
return Py_NewRef(kwstack[i]);
|
return Py_NewRef(kwstack[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue