Skip to content

Commit 37b15b8

Browse files
committed
Added if (v == w) return 1; to all compares
1 parent 201a468 commit 37b15b8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Objects/listobject.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,8 @@ unsafe_object_compare(PyObject* v, PyObject* w, CompareFuncs compare_funcs)
10921092
v->ob_type->tp_richcompare != NULL &&
10931093
v->ob_type->tp_richcompare == compare_funcs.key_richcompare);
10941094
#endif
1095-
1095+
if (v == w) return 1;
1096+
10961097
PyObject* res = (*compare_funcs.key_richcompare)(v, w, Py_LT);
10971098
if (res == NULL)
10981099
return -1;
@@ -1117,7 +1118,8 @@ unsafe_latin_compare(PyObject* v, PyObject* w, CompareFuncs compare_funcs){
11171118
PyUnicode_KIND(v) == PyUnicode_KIND(w) &&
11181119
PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND);
11191120
#endif
1120-
1121+
if (v == w) return 1;
1122+
11211123
int len = Py_MIN(PyUnicode_GET_LENGTH(v), PyUnicode_GET_LENGTH(w));
11221124
int res = memcmp(PyUnicode_DATA(v), PyUnicode_DATA(w), len);
11231125

@@ -1137,7 +1139,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, CompareFuncs compare_funcs)
11371139
Py_ABS(Py_SIZE(v)) <= 1 &&
11381140
Py_ABS(Py_SIZE(w)) <= 1);
11391141
#endif
1140-
1142+
if (v == w) return 1;
1143+
11411144
PyLongObject *vl, *wl;
11421145
vl = (PyLongObject*)v;
11431146
wl = (PyLongObject*)w;
@@ -1161,7 +1164,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, CompareFuncs compare_funcs){
11611164
assert(v->ob_type == w->ob_type &&
11621165
v->ob_type == &PyFloat_Type);
11631166
#endif
1164-
1167+
if (v == w) return 1;
1168+
11651169
return PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w);
11661170
}
11671171

@@ -1180,7 +1184,8 @@ unsafe_tuple_compare(PyObject* v, PyObject* w, CompareFuncs compare_funcs)
11801184
Py_SIZE(v) > 0 &&
11811185
Py_SIZE(w) > 0);
11821186
#endif
1183-
1187+
if (v == w) return 1;
1188+
11841189
PyTupleObject *vt, *wt;
11851190
Py_ssize_t i;
11861191
Py_ssize_t vlen, wlen;
@@ -1215,7 +1220,7 @@ unsafe_tuple_compare(PyObject* v, PyObject* w, CompareFuncs compare_funcs)
12151220

12161221
/* Out of options: v[0] == w[0]! We need to look at v[1:] and w[1:].
12171222
* We can use code copied straight from tupleobject.c:tuplerichcompare: */
1218-
for (i = 0; i < vlen && i < wlen; i++) {
1223+
for (i = 1; i < vlen && i < wlen; i++) {
12191224
k = PyObject_RichCompareBool(vt->ob_item[i],
12201225
wt->ob_item[i],
12211226
Py_EQ);

0 commit comments

Comments
 (0)