This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv_cathek
authorFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 22:59:05 +0000 (15:59 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 15 Sep 2014 13:19:31 +0000 (06:19 -0700)
This macro, intended for internal use, simplifies the code in
a couple of places.

pad.c
sv.h
util.c

diff --git a/pad.c b/pad.c
index 35c96d4..04dff00 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -2244,11 +2244,7 @@ Perl_cv_name(pTHX_ CV *cv, SV *sv)
                else {
                    sv_sethek(retsv, HvNAME_HEK(CvSTASH(cv)));
                    sv_catpvs(retsv, "::");
-                   sv_catpvn_flags(retsv, HEK_KEY(CvNAME_HEK(cv)),
-                                   HEK_LEN(CvNAME_HEK(cv)),
-                                   HEK_UTF8(CvNAME_HEK(cv))
-                                       ? SV_CATUTF8
-                                       : SV_CATBYTES);
+                   sv_cathek(retsv, CvNAME_HEK(cv));
                }
            }
            else if (CvLEXICAL(cv))
diff --git a/sv.h b/sv.h
index 753b5bb..d71b9fd 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -1970,6 +1970,12 @@ mg.c:1024: warning: left-hand operand of comma expression has no effect
                             (littlelen), SV_GMAGIC)
 #define sv_mortalcopy(sv) \
        Perl_sv_mortalcopy_flags(aTHX_ sv, SV_GMAGIC|SV_DO_COW_SVSETSV)
+#define sv_cathek(sv,hek)                                          \
+       STMT_START {                                                 \
+           HEK * const bmxk = hek;                                   \
+           sv_catpvn_flags(sv, HEK_KEY(bmxk), HEK_LEN(bmxk),          \
+                           HEK_UTF8(bmxk) ? SV_CATUTF8 : SV_CATBYTES); \
+       } STMT_END
 
 /* Should be named SvCatPVN_utf8_upgrade? */
 #define sv_catpvn_nomg_utf8_upgrade(dsv, sstr, slen, nsv)      \
diff --git a/util.c b/util.c
index d6501bd..f307138 100644 (file)
--- a/util.c
+++ b/util.c
@@ -5372,10 +5372,7 @@ Perl_get_db_sub(pTHX_ SV **svp, CV *cv)
        else {
            sv_sethek(dbsv, HvENAME_HEK(GvSTASH(gv)));
            sv_catpvs(dbsv, "::");
-           sv_catpvn_flags(
-             dbsv, GvNAME(gv), GvNAMELEN(gv),
-             GvNAMEUTF8(gv) ? SV_CATUTF8 : SV_CATBYTES
-           );
+           sv_cathek(dbsv, GvNAME_HEK(gv));
        }
     }
     else {