You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
844 B

  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 *aa, PyObject *bb)
  7. {
  8. PyUnicodeObject *a = (PyUnicodeObject *)aa;
  9. PyUnicodeObject *b = (PyUnicodeObject *)bb;
  10. if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) {
  11. assert(0 && "unicode_eq ready fail");
  12. return 0;
  13. }
  14. if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b))
  15. return 0;
  16. if (PyUnicode_GET_LENGTH(a) == 0)
  17. return 1;
  18. if (PyUnicode_KIND(a) != PyUnicode_KIND(b))
  19. return 0;
  20. return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b),
  21. PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0;
  22. }