Avoid an extra SV when creating $] and $^V
authorFather Chrysostomos <sprout@cpan.org>
Tue, 30 Aug 2011 16:42:05 +0000 (09:42 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 30 Aug 2011 19:39:39 +0000 (12:39 -0700)
Originally, GVs always had something in the SV slot.  So, when the
code for $] and $^V started replacing it with another SV, it had to
free the existing SV.

Then commit c69033f2 came along and added the PERL_DONT_CREATE_GVSV
directive.  It necessarily changed a bunch of GvSV()s to GvSVn()s in
gv_fetchpvn_flags.  But it changed these two, even though they didn’t
need it.  So, when PERL_DONT_CREATE_GVSV is true (the default), we
just create and throw away a scalar needlessly.

gv.c

diff --git a/gv.c b/gv.c
index d2d2ed2..e4c1d21 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1685,7 +1685,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
            break;
        case ']':               /* $] */
        {
-           SV * const sv = GvSVn(gv);
+           SV * const sv = GvSV(gv);
            if (!sv_derived_from(PL_patchlevel, "version"))
                upg_version(PL_patchlevel, TRUE);
            GvSV(gv) = vnumify(PL_patchlevel);
@@ -1695,7 +1695,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
        break;
        case '\026':    /* $^V */
        {
-           SV * const sv = GvSVn(gv);
+           SV * const sv = GvSV(gv);
            GvSV(gv) = new_version(PL_patchlevel);
            SvREADONLY_on(GvSV(gv));
            SvREFCNT_dec(sv);