Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend OPpTARGET_MY optimisation to state var init
ck_sassign does two things: • See if $lexical = <some op> can have the assignment optimised away (OPpTARGET_MY/targlex). • See if we have state $x = foo, which needs to run only once per closure. The former optimisation is skipped for variable declarations (‘my $x = time’), because ‘my $x’ does more than just return the SV at a pad offset. It also arranges for it to be cleared on scope exit. That does not apply to state variable. The OPpLVAL_INTRO flag (indicating the presence of ‘my’ or ‘state’ before the variable) has no run-time effect on state vars, so there is no need to skip the optimisation because of it. That optimisation destroys the assignment operator and its lhs before we get to the state var init code, which needs the lhs to do its checks. So we change the order that these checks happen, and make the state var code invoke the optimisation itself.
- Loading branch information