Module Name: src
Committed By: rmind
Date: Thu May 29 21:15:55 UTC 2014
Modified Files:
src/sys/kern: subr_hash.c
Log Message:
hashinit: replace loop with a formula.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/kern/subr_hash.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_hash.c
diff -u src/sys/kern/subr_hash.c:1.5 src/sys/kern/subr_hash.c:1.6
--- src/sys/kern/subr_hash.c:1.5 Tue Jun 5 20:51:36 2012
+++ src/sys/kern/subr_hash.c Thu May 29 21:15:55 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_hash.c,v 1.5 2012/06/05 20:51:36 rmind Exp $ */
+/* $NetBSD: subr_hash.c,v 1.6 2014/05/29 21:15:55 rmind Exp $ */
/*
* Copyright (c) 1982, 1986, 1991, 1993
@@ -37,9 +37,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_hash.c,v 1.5 2012/06/05 20:51:36 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_hash.c,v 1.6 2014/05/29 21:15:55 rmind Exp $");
#include <sys/param.h>
+#include <sys/bitops.h>
#include <sys/kmem.h>
#include <sys/systm.h>
@@ -89,10 +90,9 @@ hashinit(u_int elements, enum hashtype h
if (elements > MAXELEMENTS)
elements = MAXELEMENTS;
- for (hashsize = 1; hashsize < elements; hashsize <<= 1)
- continue;
-
+ hashsize = 1UL << (ilog2(elements - 1) + 1);
esize = hash_list_size(htype);
+
p = kmem_alloc(hashsize * esize, waitok ? KM_SLEEP : KM_NOSLEEP);
if (p == NULL)
return NULL;