Enhanced string hash to permit calculating string length on the same call
- String hashing needs to walk the entire string anyhow, might as well take advantage of this and have it return the string length to avoid having to separately call strlen() in the cases where this matters. - Move the implementation into rpmstrpool.c for inlining possibilities, rstrhash() is now just a wrapper to rstrlenhash(). The generic hash implementation could not take advantage of this anyway really.
This commit is contained in:
parent
bef4be688d
commit
76a699701c
|
@ -190,20 +190,3 @@ size_t rstrlcpy(char *dest, const char *src, size_t n)
|
|||
|
||||
return s - src - 1; /* count does not include NUL */
|
||||
}
|
||||
|
||||
unsigned int rstrhash(const char * string)
|
||||
{
|
||||
/* Jenkins One-at-a-time hash */
|
||||
unsigned int hash = 0xe4721b68;
|
||||
|
||||
while (*string != '\0') {
|
||||
hash += *string;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
string++;
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
return hash;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,34 @@ struct rpmstrPool_s {
|
|||
int nrefs; /* refcount */
|
||||
};
|
||||
|
||||
/* calculate hash and string length on at once */
|
||||
static inline unsigned int rstrlenhash(const char * str, size_t * len)
|
||||
{
|
||||
/* Jenkins One-at-a-time hash */
|
||||
unsigned int hash = 0xe4721b68;
|
||||
const char * s = str;
|
||||
|
||||
while (*s != '\0') {
|
||||
hash += *s;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
s++;
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
|
||||
if (len)
|
||||
*len = (s - str);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
unsigned int rstrhash(const char * string)
|
||||
{
|
||||
return rstrlenhash(string, NULL);
|
||||
}
|
||||
|
||||
static poolHash poolHashCreate(int numBuckets)
|
||||
{
|
||||
poolHash ht;
|
||||
|
|
Loading…
Reference in New Issue