Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 886de7a

Browse files
vstinnerpull[bot]
authored andcommitted
pythongh-124502: Remove _PyUnicode_EQ() function (python#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().
1 parent 22b3951 commit 886de7a

File tree

4 files changed

+10
-39
lines changed

4 files changed

+10
-39
lines changed

Include/internal/pycore_unicodeobject.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,7 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping(
252252

253253
extern PyObject* _PyUnicode_FormatLong(PyObject *, int, int, int);
254254

255-
/* Fast equality check when the inputs are known to be exact unicode types
256-
and where the hash values are equal (i.e. a very probable match) */
257-
extern int _PyUnicode_EQ(PyObject *, PyObject *);
258-
259-
// Equality check.
255+
// Fast equality check when the inputs are known to be exact unicode types.
260256
// Export for '_pickle' shared extension.
261257
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *, PyObject *);
262258

Objects/setobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_SSIZE_RELAXED()
4141
#include "pycore_pyerrors.h" // _PyErr_SetKeyError()
4242
#include "pycore_setobject.h" // _PySet_NextEntry() definition
43+
44+
#include "stringlib/eq.h" // unicode_eq()
4345
#include <stddef.h> // offsetof()
4446
#include "clinic/setobject.c.h"
4547

@@ -96,7 +98,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
9698
return entry;
9799
if (PyUnicode_CheckExact(startkey)
98100
&& PyUnicode_CheckExact(key)
99-
&& _PyUnicode_EQ(startkey, key))
101+
&& unicode_eq(startkey, key))
100102
return entry;
101103
table = so->table;
102104
Py_INCREF(startkey);
@@ -157,7 +159,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
157159
goto found_active;
158160
if (PyUnicode_CheckExact(startkey)
159161
&& PyUnicode_CheckExact(key)
160-
&& _PyUnicode_EQ(startkey, key))
162+
&& unicode_eq(startkey, key))
161163
goto found_active;
162164
table = so->table;
163165
Py_INCREF(startkey);

Objects/unicodeobject.c

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ _PyUnicode_InternedSize_Immortal(void)
261261
}
262262

263263
static Py_hash_t unicode_hash(PyObject *);
264-
static int unicode_compare_eq(PyObject *, PyObject *);
265264

266265
static Py_uhash_t
267266
hashtable_unicode_hash(const void *key)
@@ -275,7 +274,7 @@ hashtable_unicode_compare(const void *key1, const void *key2)
275274
PyObject *obj1 = (PyObject *)key1;
276275
PyObject *obj2 = (PyObject *)key2;
277276
if (obj1 != NULL && obj2 != NULL) {
278-
return unicode_compare_eq(obj1, obj2);
277+
return unicode_eq(obj1, obj2);
279278
}
280279
else {
281280
return obj1 == obj2;
@@ -10968,26 +10967,6 @@ unicode_compare(PyObject *str1, PyObject *str2)
1096810967
#undef COMPARE
1096910968
}
1097010969

10971-
static int
10972-
unicode_compare_eq(PyObject *str1, PyObject *str2)
10973-
{
10974-
int kind;
10975-
const void *data1, *data2;
10976-
Py_ssize_t len;
10977-
int cmp;
10978-
10979-
len = PyUnicode_GET_LENGTH(str1);
10980-
if (PyUnicode_GET_LENGTH(str2) != len)
10981-
return 0;
10982-
kind = PyUnicode_KIND(str1);
10983-
if (PyUnicode_KIND(str2) != kind)
10984-
return 0;
10985-
data1 = PyUnicode_DATA(str1);
10986-
data2 = PyUnicode_DATA(str2);
10987-
10988-
cmp = memcmp(data1, data2, len * kind);
10989-
return (cmp == 0);
10990-
}
1099110970

1099210971
int
1099310972
_PyUnicode_Equal(PyObject *str1, PyObject *str2)
@@ -10997,7 +10976,7 @@ _PyUnicode_Equal(PyObject *str1, PyObject *str2)
1099710976
if (str1 == str2) {
1099810977
return 1;
1099910978
}
11000-
return unicode_compare_eq(str1, str2);
10979+
return unicode_eq(str1, str2);
1100110980
}
1100210981

1100310982

@@ -11213,7 +11192,7 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
1121311192
return 0;
1121411193
}
1121511194

11216-
return unicode_compare_eq(left, right_uni);
11195+
return unicode_eq(left, right_uni);
1121711196
}
1121811197

1121911198
PyObject *
@@ -11241,7 +11220,7 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
1124111220
}
1124211221
}
1124311222
else if (op == Py_EQ || op == Py_NE) {
11244-
result = unicode_compare_eq(left, right);
11223+
result = unicode_eq(left, right);
1124511224
result ^= (op == Py_NE);
1124611225
return PyBool_FromLong(result);
1124711226
}
@@ -11251,12 +11230,6 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
1125111230
}
1125211231
}
1125311232

11254-
int
11255-
_PyUnicode_EQ(PyObject *aa, PyObject *bb)
11256-
{
11257-
return unicode_eq(aa, bb);
11258-
}
11259-
1126011233
int
1126111234
PyUnicode_Contains(PyObject *str, PyObject *substr)
1126211235
{

Python/getargs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
20642064
for (i = 0; i < nkwargs; i++) {
20652065
PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
20662066
assert(PyUnicode_Check(kwname));
2067-
if (_PyUnicode_EQ(kwname, key)) {
2067+
if (_PyUnicode_Equal(kwname, key)) {
20682068
return Py_NewRef(kwstack[i]);
20692069
}
20702070
}

0 commit comments

Comments
 (0)