Module Name:    src
Committed By:   rillig
Date:           Sun Aug  1 08:03:43 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: lex.c lint1.h

Log Message:
lint: remove hash value from symbol buffer

Conceptually, a symbol buffer does not need to remember its hash value
since that belongs to the symbol table.  This makes the code for the
symbol table simpler.  The number of hash calculations increases by
about 5%, which is negligible.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/xlint/lint1/lint1.h

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.61 src/usr.bin/xlint/lint1/lex.c:1.62
--- src/usr.bin/xlint/lint1/lex.c:1.61	Sun Aug  1 07:46:51 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Aug  1 08:03:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.62 2021/08/01 08:03:43 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.61 2021/08/01 07:46:51 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.62 2021/08/01 08:03:43 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -259,9 +259,11 @@ symt_t	symtyp;
 
 
 static void
-symtab_add_hash(sym_t *sym, size_t h)
+symtab_add(sym_t *sym)
 {
+	size_t h;
 
+	h = hash(sym->s_name);
 	if ((sym->s_link = symtab[h]) != NULL)
 		symtab[h]->s_rlink = &sym->s_link;
 	sym->s_rlink = &symtab[h];
@@ -269,15 +271,6 @@ symtab_add_hash(sym_t *sym, size_t h)
 }
 
 static void
-symtab_add(sym_t *sym)
-{
-	size_t h;
-
-	h = hash(sym->s_name);
-	symtab_add_hash(sym, h);
-}
-
-static void
 symtab_remove(sym_t *sym)
 {
 
@@ -445,7 +438,6 @@ lex_name(const char *yytext, size_t yyle
 	sb = allocsb();
 	sb->sb_name = yytext;
 	sb->sb_len = yyleng;
-	sb->sb_hash = hash(yytext);
 	if ((sym = search(sb)) != NULL && sym->s_keyword != NULL) {
 		freesb(sb);
 		return keyw(sym);
@@ -473,10 +465,12 @@ lex_name(const char *yytext, size_t yyle
 static sym_t *
 search(sbuf_t *sb)
 {
+	int h;
 	sym_t *sym;
 	const struct kwtab *kw;
 
-	for (sym = symtab[sb->sb_hash]; sym != NULL; sym = sym->s_link) {
+	h = hash(sb->sb_name);
+	for (sym = symtab[h]; sym != NULL; sym = sym->s_link) {
 		if (strcmp(sym->s_name, sb->sb_name) != 0)
 			continue;
 		kw = sym->s_keyword;
@@ -1471,7 +1465,7 @@ getsym(sbuf_t *sb)
 
 	symtyp = FVFT;
 
-	symtab_add_hash(sym, sb->sb_hash);
+	symtab_add(sym);
 
 	*di->d_ldlsym = sym;
 	di->d_ldlsym = &sym->s_dlnxt;

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.120 src/usr.bin/xlint/lint1/lint1.h:1.121
--- src/usr.bin/xlint/lint1/lint1.h:1.120	Sat Jul 31 19:52:44 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Aug  1 08:03:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.120 2021/07/31 19:52:44 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.121 2021/08/01 08:03:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -293,7 +293,6 @@ typedef	struct sym {
 typedef	struct sbuf {
 	const	char *sb_name;		/* name of symbol */
 	size_t	sb_len;			/* length (without '\0') */
-	int	sb_hash;		/* hash value */
 	sym_t	*sb_sym;		/* symbol table entry */
 	struct	sbuf *sb_next;		/* for freelist */
 } sbuf_t;

Reply via email to