New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CvGvNAME_HEK helper #16155
Comments
From @atoomicThis is a bug report for perl from atoomic@cpan.org, Can probably find a better name for the helper, but the idea is to get rid Note that this is saving an extra CvNAMED check from CvNAME_HEK. Flags: Site configuration information for perl 5.24.1: Configured by cPanel at Wed Sep 6 12:24:43 CDT 2017. Summary of my perl5 (revision 5 version 24 subversion 1) configuration: Platform: Locally applied patches: @INC for perl 5.24.1: /usr/local/cpanel/3rdparty/perl/524/lib64/perl5/cpanel_lib/x86_64-linux-64int /usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int Environment for perl 5.24.1: PATH=/usr/local/cpanel/3rdparty/perl/526/bin:/usr/local/cpanel/3rdparty/perl/524/bin:/usr/local/cpanel/3rdparty/perl/522/bin:/usr/local/cpanel/3rdparty/perl/514/bin:/usr/local/cpanel/3rdparty/bin:/root/bin/:/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/cpanel/composer/bin:/root/.dotfiles/bin:/root/perl5/bin:/root/.rvm/bin:/root/bin |
From @atoomicbetter with the patch, which can also be read online at atoomic@598e5c4 On Mon, 18 Sep 2017 15:42:28 -0700, atoomic@cpan.org wrote:
|
From @atoomic0001-Add-CvGvNAME_HEK-helper.patchFrom 598e5c49475d99cc3ca0d0364b342c91cabd9fc2 Mon Sep 17 00:00:00 2001
From: Nicolas R <atoomic@cpan.org>
Date: Mon, 18 Sep 2017 14:37:48 -0600
Subject: [PATCH] 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.
---
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);
--
2.14.1
|
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Mon, 18 Sep 2017 15:57:00 -0700, atoomic wrote:
Thank you. Applied as 7965633. -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#132123 (status was 'resolved')
Searchable as RT132123$
The text was updated successfully, but these errors were encountered: