You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- By not allocating a new PyLong on each iteration, we save significant
time; in a benchmark with a large range a bit more than a factor of 2,
with a small range a few percent (~8% with only interned ints)
- To make sure this doesn't break when assigning to different variables
using next(), we have to decrement the target object's reference counter
before calling iternext(). We do this by checking if the next
instruction is a STORE_FAST, and treat the FOR_ITER/STORE_FAST pair as
a sort of super-instruction, saving some pushing and popping from the
stack as well.
- We do have to be careful with DECREFing before setting the new local,
as mentioned in the comment to the SETLOCAL macro:
'This is because it is possible that during the DECREF the frame is
accessed by other code (e.g. a __del__ method or gc.collect()) and the
variable would be pointing to already-freed memory.'
Therefore we restrict this only to long types with a ref count >1
- One caveat is that range will no longer result in interned integers,
so 'for i in range(10)' will result in 'i is 5' always False.
0 commit comments