This is a waste:
/* Can clear pad variable in place? */
if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
/*
* if a my variable that was made readonly is going out of
* scope, we want to remove the readonlyness so that it can
* go out of scope quietly
*/
if (SvPADMY(sv) && !SvFAKE(sv))
SvREADONLY_off(sv);
if (SvTHINKFIRST(sv))
sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
We can simply drop the globness in sv_force_normal instead of flatten-
ing globs to strings. The same applies to COWs. The SV_COW_DROP_PV
flag accomplishes both.
Before and after:
$ time ./miniperl -e 'for (1..1000000) { my $x = *foo }'
real 0m2.324s
user 0m2.316s
sys 0m0.006s
$ time ./miniperl -e 'for (1..1000000) { my $x = *foo }'
real 0m0.848s
user 0m0.840s
sys 0m0.005s
SvREADONLY_off(sv);
if (SvTHINKFIRST(sv))
- sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
+ sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF
+ |SV_COW_DROP_PV);
if (SvTYPE(sv) == SVt_PVHV)
Perl_hv_kill_backrefs(aTHX_ MUTABLE_HV(sv));
if (SvMAGICAL(sv))