Commit d7ece166 authored by Stefan Behnel's avatar Stefan Behnel

reduced overhead for CPython in __Pyx_IterFinish() utility function

--HG--
extra : transplant_source : %E3%97%5E9%1A%97%9BR%EC%01%FD%A0%B7-%81%C5G%AD%DA%DC
parent cbd0f76c
......@@ -165,6 +165,27 @@ static CYTHON_INLINE int __Pyx_IterFinish(); /*proto*/
// detects an error that occurred in the iterator, it returns -1.
static CYTHON_INLINE int __Pyx_IterFinish() {
#if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET();
PyObject* exc_type = tstate->curexc_type;
if (unlikely(exc_type)) {
if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
PyObject *exc_value, *exc_tb;
exc_value = tstate->curexc_value;
exc_tb = tstate->curexc_traceback;
tstate->curexc_type = 0;
tstate->curexc_value = 0;
tstate->curexc_traceback = 0;
Py_DECREF(exc_type);
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
return 0;
} else {
return -1;
}
}
return 0;
#else
if (unlikely(PyErr_Occurred())) {
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
PyErr_Clear();
......@@ -174,4 +195,5 @@ static CYTHON_INLINE int __Pyx_IterFinish() {
}
}
return 0;
#endif
}
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