eq.h 610 B

1234567891011121314151617
  1. /* Fast unicode equal function optimized for dictobject.c and setobject.c */
  2. /* Return 1 if two unicode objects are equal, 0 if not.
  3. * unicode_eq() is called when the hash of two unicode objects is equal.
  4. */
  5. Py_LOCAL_INLINE(int)
  6. unicode_eq(PyObject *a, PyObject *b)
  7. {
  8. if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b))
  9. return 0;
  10. if (PyUnicode_GET_LENGTH(a) == 0)
  11. return 1;
  12. if (PyUnicode_KIND(a) != PyUnicode_KIND(b))
  13. return 0;
  14. return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b),
  15. PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0;
  16. }