We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2cd24eb commit ca28691Copy full SHA for ca28691
Objects/unicodeobject.c
@@ -11200,12 +11200,17 @@ unicode_compare(PyObject *str1, PyObject *str2)
11200
const void *data1, *data2;
11201
Py_ssize_t len1, len2, len;
11202
11203
+ // Fast path: if lengths are different, we can return immediately
11204
+ len1 = PyUnicode_GET_LENGTH(str1);
11205
+ len2 = PyUnicode_GET_LENGTH(str2);
11206
+ if (len1 != len2) {
11207
+ return (len1 < len2) ? -1 : 1;
11208
+ }
11209
+
11210
kind1 = PyUnicode_KIND(str1);
11211
kind2 = PyUnicode_KIND(str2);
11212
data1 = PyUnicode_DATA(str1);
11213
data2 = PyUnicode_DATA(str2);
- len1 = PyUnicode_GET_LENGTH(str1);
- len2 = PyUnicode_GET_LENGTH(str2);
11214
len = Py_MIN(len1, len2);
11215
11216
switch(kind1) {
0 commit comments