summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-04-28 16:33:35 +0100
committerDavid Mitchell <davem@iabyn.com>2011-05-19 14:49:42 +0100
commitf8d50d94322d5861315980980d36590a8caca5c6 (patch)
tree94fd91f4f0dae3deaeae0e6e34dcd79dcad2c0cc /hv.h
parentafbbf215a9f8470ac637c1eddc1d4f0eaa8ab090 (diff)
downloadperl-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.h28
1 files changed, 10 insertions, 18 deletions
diff --git a/hv.h b/hv.h
index eae1e70df6..358c8d8f29 100644
--- a/hv.h
+++ b/hv.h
@@ -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