summaryrefslogtreecommitdiff
path: root/gv.h
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-03-05 17:47:23 +0000
committerNicholas Clark <nick@ccl4.org>2006-03-05 17:47:23 +0000
commitacda4c6a827049c821c192cce45f6c5299c45783 (patch)
tree02139f3a8a9ace095fd0c53c69b38f1629698203 /gv.h
parent7459f06bb5d2ce197f3e9fd16e46ba87a2ab6995 (diff)
downloadperl-acda4c6a827049c821c192cce45f6c5299c45783.tar.gz
Use a HEK to store the GV's name, rather than a malloc()ed string.
Saves 1 word in each GV (no more strlen), and will also save the memory used by the string itself, as the HEK will exist already due to the key used by the symbol table for this GV. p4raw-id: //depot/perl@27379
Diffstat (limited to 'gv.h')
-rw-r--r--gv.h20
1 files changed, 8 insertions, 12 deletions
diff --git a/gv.h b/gv.h
index de8ec52dd8..c4e26c3024 100644
--- a/gv.h
+++ b/gv.h
@@ -43,26 +43,22 @@ struct gp {
assert(SvTYPE(_gv) == SVt_PVGV || SvTYPE(_gv) >= SVt_PVLV); \
&(GvXPVGV(_gv)->xnv_u.xgv_stash); \
}))
-# define GvNAME_get(gv) \
- ({ GV * const zzzz = (GV *) (gv); \
+# define GvNAME_HEK(gv) \
+ (*({ GV * const zzzz = (GV *) (gv); \
assert(isGV_with_GP(zzzz)); \
assert(SvTYPE(zzzz) == SVt_PVGV || SvTYPE(zzzz) >= SVt_PVLV); \
- 0 + (GvXPVGV(zzzz)->xgv_name); \
- })
-# define GvNAMELEN_get(gv) \
- ({ GV * const glank = (GV *) (gv); \
- assert(isGV_with_GP(glank)); \
- assert(SvTYPE(glank) == SVt_PVGV || SvTYPE(glank) >= SVt_PVLV); \
- 0 + (GvXPVGV(glank)->xgv_namelen); \
- })
+ &(GvXPVGV(zzzz)->xgv_namehek); \
+ }))
#else
# define GvGP(gv) ((gv)->sv_u.svu_gp)
# define GvFLAGS(gv) (GvXPVGV(gv)->xpv_cur)
# define GvSTASH(gv) (GvXPVGV(gv)->xnv_u.xgv_stash)
-# define GvNAME_get(gv) (0 + GvXPVGV(gv)->xgv_name)
-# define GvNAMELEN_get(gv) (0 + GvXPVGV(gv)->xgv_namelen)
+# define GvNAME_HEK(gv) (GvXPVGV(gv)->xgv_namehek)
#endif
+#define GvNAME_get(gv) (GvNAME_HEK(gv) ? HEK_KEY(GvNAME_HEK(gv)) : 0)
+#define GvNAMELEN_get(gv) (GvNAME_HEK(gv) ? HEK_LEN(GvNAME_HEK(gv)) : 0)
+
#define GvNAME(gv) GvNAME_get(gv)
#define GvNAMELEN(gv) GvNAMELEN_get(gv)