This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid creating extra SVs in gv_fullname4
authorFather Chrysostomos <sprout@cpan.org>
Mon, 10 Oct 2011 23:23:10 +0000 (16:23 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 11 Oct 2011 00:46:52 +0000 (17:46 -0700)
gv.c

diff --git a/gv.c b/gv.c
index 77baacb..8eb6f6b 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -2026,7 +2026,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
 void
 Perl_gv_fullname4(pTHX_ SV *sv, const GV *gv, const char *prefix, bool keepmain)
 {
-    SV *name;
+    const char *name;
     const HV * const hv = GvSTASH(gv);
 
     PERL_ARGS_ASSERT_GV_FULLNAME4;
@@ -2037,14 +2037,14 @@ Perl_gv_fullname4(pTHX_ SV *sv, const GV *gv, const char *prefix, bool keepmain)
     }
     sv_setpv(sv, prefix ? prefix : "");
 
-    name = HvNAME_get(hv)
-            ? sv_2mortal(newSVhek(HvNAME_HEK(hv)))
-            : newSVpvn_flags( "__ANON__", 8, SVs_TEMP );
-
-    if (keepmain || strnNE(SvPV_nolen(name), "main", SvCUR(name))) {
-       sv_catsv(sv,name);
+    if ((name = HvNAME(hv))) {
+      const STRLEN len = HvNAMELEN(hv);
+      if (keepmain || strnNE(name, "main", len)) {
+       sv_catpvn_flags(sv,name,len,HvNAMEUTF8(hv)?SV_CATUTF8:SV_CATBYTES);
        sv_catpvs(sv,"::");
+      }
     }
+    else sv_catpvs(sv,"__ANON__::");
     sv_catsv(sv,sv_2mortal(newSVhek(GvNAME_HEK(gv))));
 }