Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern hashinit: replace loop with a formula.



details:   https://anonhg.NetBSD.org/src/rev/fab54a15690a
branches:  trunk
changeset: 329577:fab54a15690a
user:      rmind <rmind%NetBSD.org@localhost>
date:      Thu May 29 21:15:55 2014 +0000

description:
hashinit: replace loop with a formula.

diffstat:

 sys/kern/subr_hash.c |  10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diffs (34 lines):

diff -r caa4c5b615ca -r fab54a15690a sys/kern/subr_hash.c
--- a/sys/kern/subr_hash.c      Thu May 29 19:08:30 2014 +0000
+++ b/sys/kern/subr_hash.c      Thu May 29 21:15:55 2014 +0000
@@ -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 @@
        if (elements > MAXELEMENTS)
                elements = MAXELEMENTS;
 
-       for (hashsize = 1; hashsize < elements; hashsize <<= 1)
-               continue;
+       hashsize = 1UL << (ilog2(elements - 1) + 1);
+       esize = hash_list_size(htype);
 
-       esize = hash_list_size(htype);
        p = kmem_alloc(hashsize * esize, waitok ? KM_SLEEP : KM_NOSLEEP);
        if (p == NULL)
                return NULL;



Home | Main Index | Thread Index | Old Index