Commit 1d467566 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] Change hash_mem to an inline function.

Implementing hash_str as hash_mem(..., strlen()) is actually quite slow,
so create a separate hash_str.

Now hash_mem has only one call site, and both are quite small, so we make them
both inline.
parent b2d37f61
......@@ -14,7 +14,7 @@
#include <linux/string.h>
#include <linux/sunrpc/msg_prot.h>
#include <linux/sunrpc/cache.h>
#include <linux/string.h>
#include <linux/hash.h>
struct svc_cred {
uid_t cr_uid;
......@@ -113,10 +113,41 @@ extern struct auth_domain *auth_unix_lookup(struct in_addr addr);
extern int auth_unix_forget_old(struct auth_domain *dom);
extern void svcauth_unix_purge(void);
extern int hash_mem(char *buf, int len, int bits);
static inline int hash_str(char *name, int bits)
static inline unsigned long hash_str(char *name, int bits)
{
unsigned long hash = 0;
unsigned long l = 0;
int len = 0;
unsigned char c;
do {
if (unlikely(!(c = *name++))) {
c = (char)len; len = -1;
}
l = (l << 8) | c;
len++;
if ((len & (BITS_PER_LONG/8-1))==0)
hash = hash_long(hash^l, BITS_PER_LONG);
} while (len);
return hash >> (BITS_PER_LONG - bits);
}
static inline unsigned long hash_mem(char *buf, int length, int bits)
{
return hash_mem(name, strlen(name), bits);
unsigned long hash = 0;
unsigned long l = 0;
int len = 0;
unsigned char c;
do {
if (len == length) {
c = (char)len; len = -1;
} else
c = *buf++;
l = (l << 8) | c;
len++;
if ((len & (BITS_PER_LONG/8-1))==0)
hash = hash_long(hash^l, BITS_PER_LONG);
} while (len);
return hash >> (BITS_PER_LONG - bits);
}
extern struct cache_detail auth_domain_cache, ip_map_cache;
......
......@@ -97,25 +97,6 @@ svc_auth_unregister(rpc_authflavor_t flavor)
* it will complain.
*/
int hash_mem(char *buf, int len, int bits)
{
int hash = 0;
unsigned long l;
while (len >= BITS_PER_LONG/8) {
l = *(unsigned long *)buf;
buf += BITS_PER_LONG/8;
len -= BITS_PER_LONG/8;
hash ^= hash_long(l, bits);
}
if (len) {
l=0;
memcpy((char*)&l, buf, len);
hash ^= hash_long(l, bits);
}
return hash;
}
/*
* Auth auth_domain cache is somewhat different to other caches,
* largely because the entries are possibly of different types:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment