diff options
author | Nicholas Clark <nick@ccl4.org> | 2006-03-05 17:47:23 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2006-03-05 17:47:23 +0000 |
commit | acda4c6a827049c821c192cce45f6c5299c45783 (patch) | |
tree | 02139f3a8a9ace095fd0c53c69b38f1629698203 /gv.h | |
parent | 7459f06bb5d2ce197f3e9fd16e46ba87a2ab6995 (diff) | |
download | perl-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.h | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -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) |