mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
bpo-45753: Make recursion checks more efficient. (GH-29524)
* Uses recursion remaining, instead of recursion depth to speed up check against recursion limit.
This commit is contained in:
parent
9bf2cbc4c4
commit
b931077375
10 changed files with 50 additions and 43 deletions
|
@ -75,12 +75,12 @@ extern void _PyEval_DeactivateOpCache(void);
|
|||
/* With USE_STACKCHECK macro defined, trigger stack checks in
|
||||
_Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */
|
||||
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
|
||||
return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit
|
||||
|| ++tstate->stackcheck_counter > 64);
|
||||
return (tstate->recursion_remaining-- <= 0
|
||||
|| (tstate->recursion_remaining & 63) == 0);
|
||||
}
|
||||
#else
|
||||
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
|
||||
return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit);
|
||||
return tstate->recursion_remaining-- <= 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -101,7 +101,7 @@ static inline int _Py_EnterRecursiveCall_inline(const char *where) {
|
|||
#define Py_EnterRecursiveCall(where) _Py_EnterRecursiveCall_inline(where)
|
||||
|
||||
static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) {
|
||||
tstate->recursion_depth--;
|
||||
tstate->recursion_remaining++;
|
||||
}
|
||||
|
||||
static inline void _Py_LeaveRecursiveCall_inline(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue