mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +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
|
@ -933,8 +933,9 @@ _PyAST_Validate(mod_ty mod)
|
|||
return 0;
|
||||
}
|
||||
/* Be careful here to prevent overflow. */
|
||||
starting_recursion_depth = (tstate->recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
|
||||
tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE : tstate->recursion_depth;
|
||||
int recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
|
||||
starting_recursion_depth = (recursion_depth< INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
|
||||
recursion_depth * COMPILER_STACK_FRAME_SCALE : recursion_depth;
|
||||
state.recursion_depth = starting_recursion_depth;
|
||||
state.recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
|
||||
recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue