scope.c: Don’t stringify globs on scope exit
authorFather Chrysostomos <sprout@cpan.org>
Mon, 30 Jul 2012 21:27:12 +0000 (14:27 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 31 Jul 2012 06:24:23 +0000 (23:24 -0700)
commita6d7a4ac1ec8155ef7c0c772e5731a362e6d9f3c
tree8d22e971d4c3482a4fdc1de3ab433f98d15a4fbe
parentf8c6801b81163debebd01aab796519234a5935d4
scope.c: Don’t stringify globs on scope exit

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
scope.c