summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-08-06 05:43:39 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-08-06 05:43:39 (GMT)
commitfe889f3c628797e5d4eb5e8cf26a783ed504a251 (patch)
tree0b41692a090a44c0d52901b34a6d509ae405c994 /Objects
parent2772c679e9c9503965301541ffa2a730c2527976 (diff)
downloadcpython-fe889f3c628797e5d4eb5e8cf26a783ed504a251.zip
cpython-fe889f3c628797e5d4eb5e8cf26a783ed504a251.tar.gz
cpython-fe889f3c628797e5d4eb5e8cf26a783ed504a251.tar.bz2
Factor away a redundant clear() function.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 356b6be..9952ec0 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -384,7 +384,7 @@ set_discard_internal(PySetObject *so, PyObject *key)
return DISCARD_FOUND;
}
-static void
+static int
set_clear_internal(PySetObject *so)
{
setentry *entry, *table;
@@ -406,7 +406,7 @@ set_clear_internal(PySetObject *so)
/* This is delicate. During the process of clearing the set,
* decrefs can cause the set to mutate. To avoid fatal confusion
* (voice of experience), we have to make the set empty before
- * clearing the slots, and never refer to anything via mp->ref while
+ * clearing the slots, and never refer to anything via so->ref while
* clearing.
*/
fill = so->fill;
@@ -445,6 +445,8 @@ set_clear_internal(PySetObject *so)
if (table_is_malloced)
PyMem_DEL(table);
+ so->hash = -1;
+ return 0;
}
/*
@@ -1433,20 +1435,11 @@ static PyObject *
set_clear(PySetObject *so)
{
set_clear_internal(so);
- so->hash = -1;
Py_RETURN_NONE;
}
PyDoc_STRVAR(clear_doc, "Remove all elements from this set.");
-static int
-set_tp_clear(PySetObject *so)
-{
- set_clear_internal(so);
- so->hash = -1;
- return 0;
-}
-
static PyObject *
set_add(PySetObject *so, PyObject *key)
{
@@ -1727,7 +1720,7 @@ PyTypeObject PySet_Type = {
Py_TPFLAGS_BASETYPE, /* tp_flags */
set_doc, /* tp_doc */
(traverseproc)set_traverse, /* tp_traverse */
- (inquiry)set_tp_clear, /* tp_clear */
+ (inquiry)set_clear_internal, /* tp_clear */
(richcmpfunc)set_richcompare, /* tp_richcompare */
offsetof(PySetObject, weakreflist), /* tp_weaklistoffset */
(getiterfunc)set_iter, /* tp_iter */
@@ -1822,7 +1815,7 @@ PyTypeObject PyFrozenSet_Type = {
Py_TPFLAGS_BASETYPE, /* tp_flags */
frozenset_doc, /* tp_doc */
(traverseproc)set_traverse, /* tp_traverse */
- 0, /* tp_clear */
+ (inquiry)set_clear_internal, /* tp_clear */
(richcmpfunc)set_richcompare, /* tp_richcompare */
offsetof(PySetObject, weakreflist), /* tp_weaklistoffset */
(getiterfunc)set_iter, /* tp_iter */