Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint lint: fold constants in hash functions



details:   https://anonhg.NetBSD.org/src/rev/fbd9c449d730
branches:  trunk
changeset: 1023183:fbd9c449d730
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 28 19:27:44 2021 +0000

description:
lint: fold constants in hash functions

All platforms supported by lint have sizeof(unsigned int) == 4 and
CHAR_BIT == 8.  There is no need to encode these expressions in a hash
function, they only made the code harder to read.

No functional change.

diffstat:

 usr.bin/xlint/lint1/lex.c  |  8 ++++----
 usr.bin/xlint/lint2/hash.c |  8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diffs (58 lines):

diff -r 4ff318d738ca -r fbd9c449d730 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Aug 28 19:00:55 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Aug 28 19:27:44 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.75 2021/08/28 18:58:24 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.76 2021/08/28 19:27:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.75 2021/08/28 18:58:24 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.76 2021/08/28 19:27:44 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -401,8 +401,8 @@
 
        v = 0;
        for (us = (const unsigned char *)s; *us != '\0'; us++) {
-               v = (v << sizeof(v)) + *us;
-               v ^= v >> (sizeof(v) * CHAR_BIT - sizeof(v));
+               v = (v << 4) + *us;
+               v ^= v >> 28;
        }
        return v % HSHSIZ1;
 }
diff -r 4ff318d738ca -r fbd9c449d730 usr.bin/xlint/lint2/hash.c
--- a/usr.bin/xlint/lint2/hash.c        Sat Aug 28 19:00:55 2021 +0000
+++ b/usr.bin/xlint/lint2/hash.c        Sat Aug 28 19:27:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.20 2021/08/28 19:00:55 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.21 2021/08/28 19:27:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: hash.c,v 1.20 2021/08/28 19:00:55 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.21 2021/08/28 19:27:44 rillig Exp $");
 #endif
 
 /*
@@ -80,8 +80,8 @@
 
        v = 0;
        for (us = (const unsigned char *)s; *us != '\0'; us++) {
-               v = (v << sizeof(v)) + *us;
-               v ^= v >> (sizeof(v) * CHAR_BIT - sizeof(v));
+               v = (v << 4) + *us;
+               v ^= v >> 28;
        }
        return v % HSHSIZ2;
 }



Home | Main Index | Thread Index | Old Index