Christian Heimes | 0ded5b5 | 2007-12-10 15:50:56 +0000 | [diff] [blame] | 1 | /* Fast unicode equal function optimized for dictobject.c and setobject.c */ |
| 2 | |
| 3 | /* Return 1 if two unicode objects are equal, 0 if not. |
| 4 | * unicode_eq() is called when the hash of two unicode objects is equal. |
| 5 | */ |
| 6 | Py_LOCAL_INLINE(int) |
| 7 | unicode_eq(PyObject *aa, PyObject *bb) |
| 8 | { |
| 9 | register PyUnicodeObject *a = (PyUnicodeObject *)aa; |
| 10 | register PyUnicodeObject *b = (PyUnicodeObject *)bb; |
| 11 | |
| 12 | if (a->length != b->length) |
| 13 | return 0; |
| 14 | if (a->length == 0) |
| 15 | return 1; |
| 16 | if (a->str[0] != b->str[0]) |
| 17 | return 0; |
| 18 | if (a->length == 1) |
| 19 | return 1; |
| 20 | return memcmp(a->str, b->str, a->length * sizeof(Py_UNICODE)) == 0; |
| 21 | } |