diff options
author | David Mitchell <davem@iabyn.com> | 2011-04-28 16:33:35 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2011-05-19 14:49:42 +0100 |
commit | f8d50d94322d5861315980980d36590a8caca5c6 (patch) | |
tree | 94fd91f4f0dae3deaeae0e6e34dcd79dcad2c0cc /hv.h | |
parent | afbbf215a9f8470ac637c1eddc1d4f0eaa8ab090 (diff) | |
download | perl-f8d50d94322d5861315980980d36590a8caca5c6.tar.gz |
unify PERL_HASH and PERL_HASH_INTERNAL
Those two macros expand into two large, almost identical chunks of code.
The only difference between the two is the source of the hash seed.
So parameterize this into a new PERL_HASH_INTERNAL_() macro.
Also, there are a couple of places in hv.c that do the rough equivalent of
if (HvREHASH(hv))
key = PERL_HASH_INTERNAL(...)
else
key = PERL_HASH(...)
which incorporates two complete macro expansions into the code.
Reorganise them to be
key = PERL_HASH_INTERNAL_(..., HvREHASH(hv))
Diffstat (limited to 'hv.h')
-rw-r--r-- | hv.h | 28 |
1 files changed, 10 insertions, 18 deletions
@@ -127,30 +127,23 @@ struct xpvhv { # define PERL_HASH_SEED 0 # endif #endif -#define PERL_HASH(hash,str,len) \ - STMT_START { \ - register const char * const s_PeRlHaSh_tmp = str; \ - register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \ - register I32 i_PeRlHaSh = len; \ - register U32 hash_PeRlHaSh = PERL_HASH_SEED; \ - while (i_PeRlHaSh--) { \ - hash_PeRlHaSh += *s_PeRlHaSh++; \ - hash_PeRlHaSh += (hash_PeRlHaSh << 10); \ - hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \ - } \ - hash_PeRlHaSh += (hash_PeRlHaSh << 3); \ - hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \ - (hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \ - } STMT_END + +#define PERL_HASH(hash,str,len) PERL_HASH_INTERNAL_(hash,str,len,0) /* Only hv.c and mod_perl should be doing this. */ #ifdef PERL_HASH_INTERNAL_ACCESS -#define PERL_HASH_INTERNAL(hash,str,len) \ +#define PERL_HASH_INTERNAL(hash,str,len) PERL_HASH_INTERNAL_(hash,str,len,1) +#endif + +/* Common base for PERL_HASH and PERL_HASH_INTERNAL that parameterises + * the source of the seed. Not for direct use outside of hv.c. */ + +#define PERL_HASH_INTERNAL_(hash,str,len,internal) \ STMT_START { \ register const char * const s_PeRlHaSh_tmp = str; \ register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \ register I32 i_PeRlHaSh = len; \ - register U32 hash_PeRlHaSh = PL_rehash_seed; \ + register U32 hash_PeRlHaSh = (internal ? PL_rehash_seed : PERL_HASH_SEED); \ while (i_PeRlHaSh--) { \ hash_PeRlHaSh += *s_PeRlHaSh++; \ hash_PeRlHaSh += (hash_PeRlHaSh << 10); \ @@ -160,7 +153,6 @@ struct xpvhv { hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \ (hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \ } STMT_END -#endif /* =head1 Hash Manipulation Functions |