summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorNeil Brown <neilb@cse.unsw.edu.au>2003-01-10 04:40:24 -0800
committerLinus Torvalds <torvalds@home.transmeta.com>2003-01-10 04:40:24 -0800
commit1d467566259b58b47d0db573e0bccee730894dd6 (patch)
treef8c16211692a7445c50444a1dc9f12c3ccefb91d /include/linux
parentb2d37f6179857f88c20fc1025a7b8118b3817fd0 (diff)
[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.
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/sunrpc/svcauth.h39
1 files changed, 35 insertions, 4 deletions
diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
index 50427c823a6f..cfc61cf5440d 100644
--- a/include/linux/sunrpc/svcauth.h
+++ b/include/linux/sunrpc/svcauth.h
@@ -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;