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( ...@@ -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; PyObject *tmpkey;
int rv; int rv;
rv = PySet_Discard(set, key);
/* Convert *key* to frozenset if necessary */
if (rv < 0) {
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
return -1; return -1;
PyErr_Clear(); PyErr_Clear();
...@@ -418,6 +415,24 @@ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) { ...@@ -418,6 +415,24 @@ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
return -1; return -1;
rv = PySet_Discard(set, tmpkey); rv = PySet_Discard(set, tmpkey);
Py_DECREF(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; return rv;
} }
...@@ -428,23 +443,15 @@ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) { ...@@ -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*/ static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key); /*proto*/
/////////////// py_set_remove /////////////// /////////////// py_set_remove ///////////////
//@requires: py_set_discard_unhashable
static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) { static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) {
PyObject *tmpkey;
int rv; int rv;
rv = PySet_Discard(set, key); rv = PySet_Discard(set, key);
/* Convert *key* to frozenset if necessary */ /* Convert *key* to frozenset if necessary */
if (rv < 0) { if (unlikely(rv < 0)) {
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) rv = __Pyx_PySet_DiscardUnhashable(set, key);
return -1;
PyErr_Clear();
tmpkey = PyFrozenSet_New(key);
if (tmpkey == NULL)
return -1;
rv = PySet_Discard(set, tmpkey);
Py_DECREF(tmpkey);
} }
if (rv == 0) { if (rv == 0) {
/* Not found */ /* 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