Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): clean up hash function for HashTable
details: https://anonhg.NetBSD.org/src/rev/a5acadd949ae
branches: trunk
changeset: 947534:a5acadd949ae
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Dec 15 15:20:05 2020 +0000
description:
make(1): clean up hash function for HashTable
Expressing a multiplication as a bit shifts and subtraction is the job
of the compiler. For humans, a multiplication is easier to read.
diffstat:
usr.bin/make/hash.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diffs (36 lines):
diff -r b2f0646a617f -r a5acadd949ae usr.bin/make/hash.c
--- a/usr.bin/make/hash.c Tue Dec 15 08:35:52 2020 +0000
+++ b/usr.bin/make/hash.c Tue Dec 15 15:20:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.c,v 1.58 2020/11/23 17:59:21 rillig Exp $ */
+/* $NetBSD: hash.c,v 1.59 2020/12/15 15:20:05 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -74,7 +74,7 @@
#include "make.h"
/* "@(#)hash.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: hash.c,v 1.58 2020/11/23 17:59:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.59 2020/12/15 15:20:05 rillig Exp $");
/*
* The ratio of # entries to # buckets at which we rebuild the table to
@@ -86,10 +86,13 @@
static unsigned int
hash(const char *key, size_t *out_keylen)
{
- unsigned int h = 0;
- const char *p = key;
- while (*p != '\0')
- h = (h << 5) - h + (unsigned char)*p++;
+ unsigned int h;
+ const char *p;
+
+ h = 0;
+ for (p = key; *p != '\0'; p++)
+ h = 31 * h + (unsigned char)*p;
+
if (out_keylen != NULL)
*out_keylen = (size_t)(p - key);
return h;
Home |
Main Index |
Thread Index |
Old Index