From: Perl 5 Porters Date: Wed, 19 Jun 1996 20:12:08 +0000 (+0000) Subject: Add shared hash key support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf6bd8876f5c82478753ddc8ce036db60ddde40e;p=p5sagit%2Fp5-mst-13.2.git Add shared hash key support --- diff --git a/hv.h b/hv.h index 4970363..a9de8ca 100644 --- a/hv.h +++ b/hv.h @@ -32,6 +32,23 @@ struct xpvhv { char *xhv_name; /* name, if a symbol table */ }; +#define PERL_HASH(hash,str,len) \ + STMT_START { \ + register char *s_PeRlHaSh = str; \ + register I32 i_PeRlHaSh = len; \ + register U32 hash_PeRlHaSh = 0; \ + while (i_PeRlHaSh--) \ + hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ + (hash) = hash_PeRlHaSh; \ + } STMT_END + + +/* these hash entry flags ride on hent_klen */ + +#define HEf_LAZYDEL -1 /* entry must be deleted during next iter step */ +#define HEf_SVKEY -2 /* hent_key is a SV* (only for magic/tied HVs) */ + + #define Nullhv Null(HV*) #define HvARRAY(hv) ((HE**)((XPVHV*) SvANY(hv))->xhv_array) #define HvFILL(hv) ((XPVHV*) SvANY(hv))->xhv_fill @@ -42,6 +59,10 @@ struct xpvhv { #define HvPMROOT(hv) ((XPVHV*) SvANY(hv))->xhv_pmroot #define HvNAME(hv) ((XPVHV*) SvANY(hv))->xhv_name +#define HvSHAREKEYS(hv) (SvFLAGS(hv) & SVphv_SHAREKEYS) +#define HvSHAREKEYS_on(hv) (SvFLAGS(hv) |= SVphv_SHAREKEYS) +#define HvSHAREKEYS_off(hv) (SvFLAGS(hv) &= ~SVphv_SHAREKEYS) + #ifdef OVERLOAD /* Maybe amagical: */ @@ -58,3 +79,23 @@ struct xpvhv { */ #endif /* OVERLOAD */ + +#define Nullhe Null(HE*) +#define HeNEXT(he) (he)->hent_next +#define HeKEY(he) (he)->hent_key +#define HeKLEN(he) (he)->hent_klen +#define HeVAL(he) (he)->hent_val +#define HeHASH(he) (he)->hent_hash +#define HePV(he) ((he)->hent_klen == HEf_SVKEY) ? \ + SvPV((SV*)((he)->hent_key),na) : \ + (he)->hent_key)) +#define HeSVKEY(he) (((he)->hent_key && \ + (he)->hent_klen == HEf_SVKEY) ? \ + (SV*)((he)->hent_key) : Nullsv) + +#define HeSVKEY_force(he) ((he)->hent_key ? \ + (((he)->hent_klen == HEf_SVKEY) ? \ + (SV*)((he)->hent_key) : \ + sv_2mortal(newSVpv((he)->hent_key, \ + (he)->hent_klen))) : \ + &sv_undef) diff --git a/sv.h b/sv.h index c586de4..5b3a72a 100644 --- a/sv.h +++ b/sv.h @@ -129,6 +129,8 @@ struct io { #define SVpbm_CASEFOLD 0x40000000 #define SVpbm_TAIL 0x20000000 +#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ + #ifdef OVERLOAD #define SVpgv_AM 0x40000000 /* #define SVpgv_badAM 0x20000000 */