summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-08-24 00:24:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-08-24 00:24:40 (GMT)
commit9c1491f37c4884d72b18a0493c757e7c1f5e2814 (patch)
treea78a314663ba912ae9c2aca2afb71a616fcc6a03 /Objects/setobject.c
parent26292a3af08927e7a14786dd88dfd48f8ca4bd20 (diff)
downloadcpython-9c1491f37c4884d72b18a0493c757e7c1f5e2814.zip
cpython-9c1491f37c4884d72b18a0493c757e7c1f5e2814.tar.gz
cpython-9c1491f37c4884d72b18a0493c757e7c1f5e2814.tar.bz2
* Add a fast equality check path for frozensets where the hash value has
already been computed. * Apply a GET_SIZE macro().
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 9a54aed..8787347 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1495,12 +1495,15 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
case Py_EQ:
if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
Py_RETURN_FALSE;
+ if (v->hash != -1 &&
+ ((PySetObject *)w)->hash != -1 &&
+ v->hash != ((PySetObject *)w)->hash)
+ Py_RETURN_FALSE;
return set_issubset(v, w);
case Py_NE:
- if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
- Py_RETURN_TRUE;
- r1 = set_issubset(v, w);
- assert (r1 != NULL);
+ r1 = set_richcompare(v, w, Py_EQ);
+ if (r1 == NULL)
+ return NULL;
r2 = PyBool_FromLong(PyObject_Not(r1));
Py_DECREF(r1);
return r2;
@@ -1956,7 +1959,7 @@ PySet_Size(PyObject *anyset)
PyErr_BadInternalCall();
return -1;
}
- return ((PySetObject *)anyset)->used;
+ return PySet_GET_SIZE(anyset);
}
int