mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fixed issue #1564: The set implementation should special-case PyUnicode instead of PyString
I moved the unicode_eq to stringlib/eq.h to keep the function static and possible inline for setobject.c and dictobject.h. I also removed the unused _PyString_Eq method. If it's required in the future it can be added to eq.h
This commit is contained in:
parent
110194048e
commit
0ded5b54bb
7 changed files with 85 additions and 45 deletions
21
Objects/stringlib/eq.h
Normal file
21
Objects/stringlib/eq.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* Fast unicode equal function optimized for dictobject.c and setobject.c */
|
||||
|
||||
/* Return 1 if two unicode objects are equal, 0 if not.
|
||||
* unicode_eq() is called when the hash of two unicode objects is equal.
|
||||
*/
|
||||
Py_LOCAL_INLINE(int)
|
||||
unicode_eq(PyObject *aa, PyObject *bb)
|
||||
{
|
||||
register PyUnicodeObject *a = (PyUnicodeObject *)aa;
|
||||
register PyUnicodeObject *b = (PyUnicodeObject *)bb;
|
||||
|
||||
if (a->length != b->length)
|
||||
return 0;
|
||||
if (a->length == 0)
|
||||
return 1;
|
||||
if (a->str[0] != b->str[0])
|
||||
return 0;
|
||||
if (a->length == 1)
|
||||
return 1;
|
||||
return memcmp(a->str, b->str, a->length * sizeof(Py_UNICODE)) == 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue