summaryrefslogtreecommitdiff
path: root/cv.h
diff options
context:
space:
mode:
authorNicolas R <atoomic@cpan.org>2017-09-18 14:37:48 -0600
committerFather Chrysostomos <sprout@cpan.org>2017-09-21 07:07:49 -0700
commit79656330a0811b95642a8239e923166ada7fb0a0 (patch)
treef096cb3c9e14bfb87ea704d6c96027285aea6b12 /cv.h
parentbd588a132b9686974e12bf262d1ba6c885895122 (diff)
downloadperl-79656330a0811b95642a8239e923166ada7fb0a0.tar.gz
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.
Diffstat (limited to 'cv.h')
-rw-r--r--cv.h12
1 files changed, 11 insertions, 1 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)) \