Commit b16c07dc authored by Antoine Pitrou's avatar Antoine Pitrou

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

parent 66221af5
......@@ -397,19 +397,16 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(
}
/////////////// py_set_discard.proto ///////////////
/////////////// py_set_discard_unhashable.proto ///////////////
static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key); /*proto*/
static int __Pyx_PySet_DiscardUnhashable(PyObject *set, PyObject *key); /* proto */
/////////////// py_set_discard ///////////////
/////////////// py_set_discard_unhashable ///////////////
static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
static int __Pyx_PySet_DiscardUnhashable(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();
......@@ -418,6 +415,24 @@ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
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) {
int rv;
rv = PySet_Discard(set, key);
/* Convert *key* to frozenset if necessary */
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