Commit b16c07dc authored by Antoine Pitrou's avatar Antoine Pitrou

Factor out unlikely code path in set.remove() and set.discard()

parent 66221af5
......@@ -397,27 +397,42 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(
}
/////////////// py_set_discard_unhashable.proto ///////////////
static int __Pyx_PySet_DiscardUnhashable(PyObject *set, PyObject *key); /* proto */
/////////////// py_set_discard_unhashable ///////////////
static int __Pyx_PySet_DiscardUnhashable(PyObject *set, PyObject *key) {
PyObject *tmpkey;
int rv;
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
return -1;
PyErr_Clear();
tmpkey = PyFrozenSet_New(key);
if (tmpkey == NULL)
return -1;
rv = PySet_Discard(set, tmpkey);
Py_DECREF(tmpkey);
return rv;
}
/////////////// py_set_discard.proto ///////////////
static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key); /*proto*/
/////////////// py_set_discard ///////////////
//@requires: py_set_discard_unhashable
static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
PyObject *tmpkey;
int rv;
rv = PySet_Discard(set, key);
/* Convert *key* to frozenset if necessary */
if (rv < 0) {
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
return -1;
PyErr_Clear();
tmpkey = PyFrozenSet_New(key);
if (tmpkey == NULL)
return -1;
rv = PySet_Discard(set, tmpkey);
Py_DECREF(tmpkey);
if (unlikely(rv < 0)) {
return __Pyx_PySet_DiscardUnhashable(set, key);
}
return rv;
}
......@@ -428,23 +443,15 @@ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key); /*proto*/
/////////////// py_set_remove ///////////////
//@requires: py_set_discard_unhashable
static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) {
PyObject *tmpkey;
int rv;
rv = PySet_Discard(set, key);
/* Convert *key* to frozenset if necessary */
if (rv < 0) {
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
return -1;
PyErr_Clear();
tmpkey = PyFrozenSet_New(key);
if (tmpkey == NULL)
return -1;
rv = PySet_Discard(set, tmpkey);
Py_DECREF(tmpkey);
if (unlikely(rv < 0)) {
rv = __Pyx_PySet_DiscardUnhashable(set, key);
}
if (rv == 0) {
/* Not found */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment