It was already implemented in PyUnicode_RichCompare()
);
/* Compare two strings and return -1, 0, 1 for less than, equal,
- greater than resp. */
+ greater than resp.
+ Raise an exception and return -1 on error. */
PyAPI_FUNC(int) PyUnicode_Compare(
PyObject *left, /* Left string */
void *data1, *data2;
Py_ssize_t len1, len2, i;
+ /* a string is equal to itself */
+ if (str1 == str2)
+ return 0;
+
kind1 = PyUnicode_KIND(str1);
kind2 = PyUnicode_KIND(str2);
data1 = PyUnicode_DATA(str1);
return Py_True;
}
}
- if (left == right)
- result = 0;
- else
- result = unicode_compare(left, right);
+ result = unicode_compare(left, right);
/* Convert the return value to a Boolean */
switch (op) {