In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/79656330a0811b95642a8239e923166ada7fb0a0?hp=bd588a132b9686974e12bf262d1ba6c885895122>
- Log ----------------------------------------------------------------- commit 79656330a0811b95642a8239e923166ada7fb0a0 Author: Nicolas R <atoo...@cpan.org> Date: Mon Sep 18 14:37:48 2017 -0600 Add CvGvNAME_HEK helper CvGvNAME_HEK can be used instead of the boilerplate: CvNAMED(sv) ? CvNAME_HEK((CV *)sv) : GvNAME_HEK(CvGV(sv)) This is also saving an extra CvNAMED check from CvNAME_HEK. ----------------------------------------------------------------------- Summary of changes: cv.h | 12 +++++++++++- gv.c | 3 +-- scope.c | 9 ++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cv.h b/cv.h index ebbdd360f3..dac83fa873 100644 --- a/cv.h +++ b/cv.h @@ -234,7 +234,17 @@ CvNAME_HEK(CV *sv) ? ((XPVCV*)MUTABLE_PTR(SvANY(sv)))->xcv_gv_u.xcv_hek : 0; } -/* This lowers the refernce count of the previous value, but does *not* + +/* helper for the common pattern: + CvNAMED(sv) ? CvNAME_HEK((CV *)sv) : GvNAME_HEK(CvGV(sv)) +*/ +#define CvGvNAME_HEK(sv) ( \ + CvNAMED((CV*)sv) ? \ + ((XPVCV*)MUTABLE_PTR(SvANY((SV*)sv)))->xcv_gv_u.xcv_hek\ + : GvNAME_HEK(CvGV( (SV*) sv)) \ + ) + +/* This lowers the reference count of the previous value, but does *not* increment the reference count of the new value. */ #define CvNAME_HEK_set(cv, hek) ( \ CvNAME_HEK((CV *)(cv)) \ diff --git a/gv.c b/gv.c index cfe4be572c..6df78cc013 100644 --- a/gv.c +++ b/gv.c @@ -2799,8 +2799,7 @@ Perl_Gv_AMupdate(pTHX_ HV *stash, bool destructing) gv = Perl_gv_fetchmeth_pvn(aTHX_ stash, cooky, l, -1, 0); cv = 0; if (gv && (cv = GvCV(gv)) && CvHASGV(cv)) { - const HEK * const gvhek = - CvNAMED(cv) ? CvNAME_HEK(cv) : GvNAME_HEK(CvGV(cv)); + const HEK * const gvhek = CvGvNAME_HEK(cv); const HEK * const stashek = HvNAME_HEK(CvNAMED(cv) ? CvSTASH(cv) : GvSTASH(CvGV(cv))); if (HEK_LEN(gvhek) == 3 && strEQ(HEK_KEY(gvhek), "nil") diff --git a/scope.c b/scope.c index 59cea3b985..dfaab806aa 100644 --- a/scope.c +++ b/scope.c @@ -1194,10 +1194,7 @@ Perl_leave_scope(pTHX_ I32 base) break; case SVt_PVCV: { - HEK *hek = - CvNAMED(sv) - ? CvNAME_HEK((CV *)sv) - : GvNAME_HEK(CvGV(sv)); + HEK *hek = CvGvNAME_HEK(sv); assert(hek); (void)share_hek_hek(hek); cv_undef((CV *)sv); @@ -1223,9 +1220,7 @@ Perl_leave_scope(pTHX_ I32 base) case SVt_PVHV: *svp = MUTABLE_SV(newHV()); break; case SVt_PVCV: { - HEK * const hek = CvNAMED(sv) - ? CvNAME_HEK((CV *)sv) - : GvNAME_HEK(CvGV(sv)); + HEK * const hek = CvGvNAME_HEK(sv); /* Create a stub */ *svp = newSV_type(SVt_PVCV); -- Perl5 Master Repository