Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: remove hash value from symbol buffer



details:   https://anonhg.NetBSD.org/src/rev/3b475b548670
branches:  trunk
changeset: 1022665:3b475b548670
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 01 08:03:43 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/lex.c   |  26 ++++++++++----------------
 usr.bin/xlint/lint1/lint1.h |   3 +--
 2 files changed, 11 insertions(+), 18 deletions(-)

diffs (93 lines):

diff -r 563b1a0b400c -r 3b475b548670 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Aug 01 07:46:51 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Aug 01 08:03:43 2021 +0000
@@ -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,22 +259,15 @@
 
 
 static void
-symtab_add_hash(sym_t *sym, size_t h)
-{
-
-       if ((sym->s_link = symtab[h]) != NULL)
-               symtab[h]->s_rlink = &sym->s_link;
-       sym->s_rlink = &symtab[h];
-       symtab[h] = sym;
-}
-
-static void
 symtab_add(sym_t *sym)
 {
        size_t h;
 
        h = hash(sym->s_name);
-       symtab_add_hash(sym, h);
+       if ((sym->s_link = symtab[h]) != NULL)
+               symtab[h]->s_rlink = &sym->s_link;
+       sym->s_rlink = &symtab[h];
+       symtab[h] = sym;
 }
 
 static void
@@ -445,7 +438,6 @@
        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 @@
 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 @@
 
        symtyp = FVFT;
 
-       symtab_add_hash(sym, sb->sb_hash);
+       symtab_add(sym);
 
        *di->d_ldlsym = sym;
        di->d_ldlsym = &sym->s_dlnxt;
diff -r 563b1a0b400c -r 3b475b548670 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Aug 01 07:46:51 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Aug 01 08:03:43 2021 +0000
@@ -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 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;



Home | Main Index | Thread Index | Old Index