summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-07-30 14:27:12 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-07-30 23:24:23 -0700
commita6d7a4ac1ec8155ef7c0c772e5731a362e6d9f3c (patch)
tree8d22e971d4c3482a4fdc1de3ab433f98d15a4fbe /scope.c
parentf8c6801b81163debebd01aab796519234a5935d4 (diff)
downloadperl-a6d7a4ac1ec8155ef7c0c772e5731a362e6d9f3c.tar.gz
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
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/scope.c b/scope.c
index 2a9b3d5401..d42aa8051b 100644
--- a/scope.c
+++ b/scope.c
@@ -911,7 +911,8 @@ Perl_leave_scope(pTHX_ I32 base)
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))