Module Name: src Committed By: rillig Date: Sat Aug 28 19:27:44 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: lex.c src/usr.bin/xlint/lint2: hash.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/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/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.75 src/usr.bin/xlint/lint1/lex.c:1.76 --- src/usr.bin/xlint/lint1/lex.c:1.75 Sat Aug 28 18:58:24 2021 +++ src/usr.bin/xlint/lint1/lex.c Sat Aug 28 19:27:44 2021 @@ -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 @@ hash(const char *s) 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; } Index: src/usr.bin/xlint/lint2/hash.c diff -u src/usr.bin/xlint/lint2/hash.c:1.20 src/usr.bin/xlint/lint2/hash.c:1.21 --- src/usr.bin/xlint/lint2/hash.c:1.20 Sat Aug 28 19:00:55 2021 +++ src/usr.bin/xlint/lint2/hash.c Sat Aug 28 19:27:44 2021 @@ -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 @@ hash(const char *s) 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; }