diff options
author | Nicholas Clark <nick@ccl4.org> | 2005-06-01 14:33:14 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2005-06-01 14:33:14 +0000 |
commit | b79f7545f218479c6361e25f42849d88b9cef87e (patch) | |
tree | dd31c7556d5e1a467d5dfb3610c5df0ba7507ed4 /hv.h | |
parent | ae7e4cc14be2e40a3d39a27af7d2e07ebcc705e9 (diff) | |
download | perl-b79f7545f218479c6361e25f42849d88b9cef87e.tar.gz |
Store the xhv_aux structure after the main array.
This reduces the size of HV bodies from 24 to 20 bytes on a 32 bit
build. It has the side effect of defined %symbol_table:: now always
being true. defined %hash is already deprecated.
p4raw-id: //depot/perl@24660
Diffstat (limited to 'hv.h')
-rw-r--r-- | hv.h | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -39,6 +39,8 @@ struct xpvhv_aux { I32 xhv_riter; /* current root of iterator */ }; +#define HV_AUX_SIZE STRUCT_OFFSET(struct xpvhv_aux, xhv_array) + /* hash structure: */ /* This structure must match the beginning of struct xpvmg in sv.h. */ struct xpvhv { @@ -52,7 +54,6 @@ struct xpvhv { } xiv_u; MAGIC* xmg_magic; /* magic for scalar array */ HV* xmg_stash; /* class package */ - struct xpvhv_aux *xhv_aux; }; #define xhv_keys xiv_u.xivu_iv @@ -70,7 +71,6 @@ typedef struct { } xiv_u; MAGIC* xmg_magic; /* magic for scalar array */ HV* xmg_stash; /* class package */ - struct xpvhv_aux *xhv_aux; } xpvhv_allocated; #endif @@ -206,23 +206,24 @@ C<SV*>. #define HvARRAY(hv) (*(HE***)&((hv)->sv_u.svu_array)) #define HvFILL(hv) ((XPVHV*) SvANY(hv))->xhv_fill #define HvMAX(hv) ((XPVHV*) SvANY(hv))->xhv_max +/* This quite intentionally does no flag checking first. That's your + responsibility. */ +#define HvAUX(hv) ((struct xpvhv_aux*)&(HvARRAY(hv)[HvMAX(hv)+1])) #define HvRITER(hv) (*Perl_hv_riter_p(aTHX_ (HV*)(hv))) #define HvEITER(hv) (*Perl_hv_eiter_p(aTHX_ (HV*)(hv))) #define HvRITER_set(hv,r) Perl_hv_riter_set(aTHX_ (HV*)(hv), r) #define HvEITER_set(hv,e) Perl_hv_eiter_set(aTHX_ (HV*)(hv), e) -#define HvRITER_get(hv) (((XPVHV *)SvANY(hv))->xhv_aux ? \ - ((struct xpvhv_aux*)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_riter : -1) -#define HvEITER_get(hv) (((XPVHV *)SvANY(hv))->xhv_aux ? \ - ((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_eiter : 0) +#define HvRITER_get(hv) (SvOOK(hv) ? HvAUX(hv)->xhv_riter : -1) +#define HvEITER_get(hv) (SvOOK(hv) ? HvAUX(hv)->xhv_eiter : 0) #define HvNAME(hv) HvNAME_get(hv) /* FIXME - all of these should use a UTF8 aware API, which should also involve getting the length. */ /* This macro may go away without notice. */ -#define HvNAME_HEK(hv) (((XPVHV *)SvANY(hv))->xhv_aux && (((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) ? ((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name: 0) -#define HvNAME_get(hv) (((XPVHV *)SvANY(hv))->xhv_aux ? \ - (((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) ? HEK_KEY(((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) : 0 : 0) -#define HvNAMELEN_get(hv) (((XPVHV *)SvANY(hv))->xhv_aux ? \ - (((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) ? HEK_LEN(((struct xpvhv_aux *)((XPVHV *)SvANY(hv))->xhv_aux)->xhv_name) : 0 : 0) +#define HvNAME_HEK(hv) (SvOOK(hv) ? HvAUX(hv)->xhv_name : 0) +#define HvNAME_get(hv) ((SvOOK(hv) && (HvAUX(hv)->xhv_name)) \ + ? HEK_KEY(HvAUX(hv)->xhv_name) : 0) +#define HvNAMELEN_get(hv) ((SvOOK(hv) && (HvAUX(hv)->xhv_name)) \ + ? HEK_LEN(HvAUX(hv)->xhv_name) : 0) /* the number of keys (including any placeholers) */ #define XHvTOTALKEYS(xhv) ((xhv)->xhv_keys) |