Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4300,6 +4300,15 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
res = Py_NotImplemented;
}
else if (op == Py_EQ || op == Py_NE) {
if (v == w) {
switch (op) {
case Py_EQ:
/* a list is equal to itself */
Py_RETURN_TRUE;
case Py_NE:
Py_RETURN_FALSE;
}
}
cmp = dict_equal((PyDictObject *)v, (PyDictObject *)w);
if (cmp < 0)
return NULL;
Expand Down
17 changes: 17 additions & 0 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,23 @@ list_richcompare_impl(PyObject *v, PyObject *w, int op)
vl = (PyListObject *)v;
wl = (PyListObject *)w;

if (vl == wl) {
switch (op) {
case Py_EQ:
case Py_LE:
case Py_GE:
/* a list is equal to itself */
Py_RETURN_TRUE;
case Py_NE:
case Py_LT:
case Py_GT:
Py_RETURN_FALSE;
default:
PyErr_BadArgument();
return NULL;
}
}

if (Py_SIZE(vl) != Py_SIZE(wl) && (op == Py_EQ || op == Py_NE)) {
/* Shortcut: if the lengths differ, the lists differ */
if (op == Py_EQ)
Expand Down
17 changes: 17 additions & 0 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,23 @@ set_richcompare(PyObject *self, PyObject *w, int op)
if(!PyAnySet_Check(w))
Py_RETURN_NOTIMPLEMENTED;

if (v == w) {
switch (op) {
case Py_EQ:
case Py_LE:
case Py_GE:
/* a list is equal to itself */
Py_RETURN_TRUE;
case Py_NE:
case Py_LT:
case Py_GT:
Py_RETURN_FALSE;
default:
PyErr_BadArgument();
return NULL;
}
}

switch (op) {
case Py_EQ:
if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
Expand Down
17 changes: 17 additions & 0 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,23 @@ tuple_richcompare(PyObject *v, PyObject *w, int op)
vt = (PyTupleObject *)v;
wt = (PyTupleObject *)w;

if (vt == wt) {
switch (op) {
case Py_EQ:
case Py_LE:
case Py_GE:
/* a list is equal to itself */
Py_RETURN_TRUE;
case Py_NE:
case Py_LT:
case Py_GT:
Py_RETURN_FALSE;
default:
PyErr_BadArgument();
return NULL;
}
}

vlen = Py_SIZE(vt);
wlen = Py_SIZE(wt);

Expand Down