Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/common lint: merge duplicate code for internin...



details:   https://anonhg.NetBSD.org/src/rev/0393aa909710
branches:  trunk
changeset: 950293:0393aa909710
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 24 11:55:57 2021 +0000

description:
lint: merge duplicate code for interning type names

diffstat:

 usr.bin/xlint/common/tyname.c |  25 +++++++++----------------
 1 files changed, 9 insertions(+), 16 deletions(-)

diffs (56 lines):

diff -r bb226860e530 -r 0393aa909710 usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Sun Jan 24 11:34:01 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Sun Jan 24 11:55:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.24 2021/01/16 16:53:23 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.25 2021/01/24 11:55:57 rillig Exp $       */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.24 2021/01/16 16:53:23 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.25 2021/01/24 11:55:57 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -82,10 +82,10 @@
 }
 
 /* Return the canonical instance of the string, with unlimited life time. */
-static const char *
+static const char * __noinline
 intern(const char *name)
 {
-       name_tree_node *n = type_names;
+       name_tree_node *n = type_names, **next;
        int cmp;
 
        if (n == NULL) {
@@ -95,19 +95,12 @@
        }
 
        while ((cmp = strcmp(name, n->ntn_name)) != 0) {
-               if (cmp < 0) {
-                       if (n->ntn_less == NULL) {
-                               n->ntn_less = new_name_tree_node(name);
-                               return n->ntn_less->ntn_name;
-                       }
-                       n = n->ntn_less;
-               } else {
-                       if (n->ntn_greater == NULL) {
-                               n->ntn_greater = new_name_tree_node(name);
-                               return n->ntn_greater->ntn_name;
-                       }
-                       n = n->ntn_greater;
+               next = cmp < 0 ? &n->ntn_less : &n->ntn_greater;
+               if (*next == NULL) {
+                       *next = new_name_tree_node(name);
+                       return (*next)->ntn_name;
                }
+               n = *next;
        }
        return n->ntn_name;
 }



Home | Main Index | Thread Index | Old Index