Refactor set.discard() and set.remove().

This commit is contained in:
Raymond Hettinger 2003-12-13 18:53:18 +00:00
parent 6a8bbdbe7b
commit 0deab62704

View file

@ -777,21 +777,19 @@ This has no effect if the element is already present.");
static PyObject *
set_remove(PySetObject *so, PyObject *item)
{
PyObject *tmp;
PyObject *tmp, *result;
if (PyDict_DelItem(so->data, item) == -1) {
if (!PyType_IsSubtype(item->ob_type, &PySet_Type))
return NULL;
PyErr_Clear();
if (PyType_IsSubtype(item->ob_type, &PySet_Type)) {
tmp = frozenset_dict_wrapper(((PySetObject *)(item))->data);
if (tmp == NULL)
return NULL;
if (PyDict_DelItem(so->data, tmp) == -1) {
result = set_remove(so, tmp);
Py_DECREF(tmp);
return result;
}
if (PyDict_DelItem(so->data, item) == -1)
return NULL;
}
Py_DECREF(tmp);
}
Py_INCREF(Py_None);
return Py_None;
}
@ -804,28 +802,21 @@ If the element is not a member, raise a KeyError.");
static PyObject *
set_discard(PySetObject *so, PyObject *item)
{
PyObject *tmp;
PyObject *tmp, *result;
if (PyDict_DelItem(so->data, item) == -1) {
if (PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_Clear();
else {
if (!PyType_IsSubtype(item->ob_type, &PySet_Type))
return NULL;
PyErr_Clear();
if (PyType_IsSubtype(item->ob_type, &PySet_Type)) {
tmp = frozenset_dict_wrapper(((PySetObject *)(item))->data);
if (tmp == NULL)
return NULL;
if (PyDict_DelItem(so->data, tmp) == -1) {
if (PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_Clear();
else {
result = set_discard(so, tmp);
Py_DECREF(tmp);
return result;
}
if (PyDict_DelItem(so->data, item) == -1) {
if (!PyErr_ExceptionMatches(PyExc_KeyError))
return NULL;
}
}
Py_DECREF(tmp);
}
PyErr_Clear();
}
Py_INCREF(Py_None);
return Py_None;