Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): inline and remove LstNode_Prev and Lst...



details:   https://anonhg.NetBSD.org/src/rev/7078bf109f3a
branches:  trunk
changeset: 955320:7078bf109f3a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 26 17:15:20 2020 +0000

description:
make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary.  The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically.  (On the execution level, the
function calls had been inlined anyway.)

diffstat:

 usr.bin/make/dir.c  |  13 ++++++-------
 usr.bin/make/job.c  |  10 +++++-----
 usr.bin/make/lst.c  |   7 +++----
 usr.bin/make/lst.h  |  12 +++---------
 usr.bin/make/main.c |   8 ++++----
 usr.bin/make/make.c |   6 +++---
 usr.bin/make/meta.c |   6 +++---
 usr.bin/make/suff.c |  19 +++++++++----------
 usr.bin/make/targ.c |  20 ++++++++++----------
 9 files changed, 46 insertions(+), 55 deletions(-)

diffs (truncated from 358 to 300 lines):

diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.147 2020/09/25 06:49:13 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.148 2020/09/26 17:15:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -134,7 +134,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.147 2020/09/25 06:49:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.148 2020/09/26 17:15:20 rillig Exp $");
 
 #define DIR_DEBUG0(fmt) \
     if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt)
@@ -1705,10 +1705,9 @@
 Dir_Concat(SearchPath *path1, SearchPath *path2)
 {
     SearchPathNode *ln;
-    CachedDir *dir;
 
-    for (ln = Lst_First(path2); ln != NULL; ln = LstNode_Next(ln)) {
-       dir = LstNode_Datum(ln);
+    for (ln = path2->first; ln != NULL; ln = ln->next) {
+       CachedDir *dir = ln->datum;
        if (Lst_FindDatum(path1, dir) == NULL) {
            dir->refCount += 1;
            Lst_Append(path1, dir);
@@ -1746,8 +1745,8 @@
 Dir_PrintPath(SearchPath *path)
 {
     SearchPathNode *node;
-    for (node = Lst_First(path); node != NULL; node = LstNode_Next(node)) {
-       const CachedDir *dir = LstNode_Datum(node);
+    for (node = path->first; node != NULL; node = node->next) {
+       const CachedDir *dir = node->datum;
        fprintf(debug_file, "%s ", dir->name);
     }
 }
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/job.c        Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.240 2020/09/26 16:55:58 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.241 2020/09/26 17:15:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -140,7 +140,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.240 2020/09/26 16:55:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.241 2020/09/26 17:15:20 rillig Exp $");
 
 # define STATIC static
 
@@ -689,7 +689,7 @@
        job->node->type |= OP_SAVE_CMDS;
        if ((job->flags & JOB_IGNDOTS) == 0) {
            StringListNode *dotsNode = Lst_FindDatum(job->node->commands, cmd);
-           job->tailCmds = dotsNode != NULL ? LstNode_Next(dotsNode) : NULL;
+           job->tailCmds = dotsNode != NULL ? dotsNode->next : NULL;
            return 1;
        }
        return 0;
@@ -884,8 +884,8 @@
 {
     StringListNode *node;
 
-    for (node = job->tailCmds; node != NULL; node = LstNode_Next(node)) {
-       char *cmd = LstNode_Datum(node);
+    for (node = job->tailCmds; node != NULL; node = node->next) {
+       const char *cmd = node->datum;
        char *expanded_cmd;
        /* XXX: This Var_Subst is only intended to expand the dynamic
         * variables such as .TARGET, .IMPSRC.  It is not intended to
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.71 2020/09/25 04:18:11 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.72 2020/09/26 17:15:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.71 2020/09/25 04:18:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.72 2020/09/26 17:15:20 rillig Exp $");
 
 /* Allocate and initialize a list node.
  *
@@ -290,8 +290,7 @@
 /* Return the first node from the list, starting at the given node, for which
  * the match function returns TRUE, or NULL if none of the nodes matches.
  *
- * The start node may be NULL, in which case nothing is found. This allows
- * for passing Lst_First or LstNode_Next as the start node. */
+ * The start node may be NULL, in which case nothing is found. */
 ListNode *
 Lst_FindFrom(List *list, ListNode *node, LstFindProc match, const void *matchArgs)
 {
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.68 2020/09/25 15:54:50 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.69 2020/09/26 17:15:20 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -88,8 +88,8 @@
 typedef        struct ListNode ListNode;
 
 struct ListNode {
-    ListNode *prev;            /* previous element in list */
-    ListNode *next;            /* next in list */
+    ListNode *prev;            /* previous node in list, or NULL */
+    ListNode *next;            /* next node in list, or NULL */
     uint8_t priv_useCount;     /* Count of functions using the node.
                                 * node may not be deleted until count
                                 * goes to 0 */
@@ -175,12 +175,6 @@
 
 /* Node-specific functions */
 
-/* Return the successor of the node, or NULL. */
-static inline MAKE_ATTR_UNUSED ListNode *
-LstNode_Next(ListNode *node) { return node->next; }
-/* Return the predecessor of the node, or NULL. */
-static inline MAKE_ATTR_UNUSED ListNode *
-LstNode_Prev(ListNode *node) { return node->prev; }
 /* Return the datum of the node. Usually not NULL. */
 static inline MAKE_ATTR_UNUSED void *
 LstNode_Datum(ListNode *node) { return node->datum; }
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/main.c       Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.347 2020/09/26 16:55:58 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.348 2020/09/26 17:15:20 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #endif
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.347 2020/09/26 16:55:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.348 2020/09/26 17:15:20 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
  The Regents of the University of California.  All rights reserved.");
@@ -869,8 +869,8 @@
        else
                expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
 
-       for (ln = Lst_First(variables); ln != NULL; ln = LstNode_Next(ln)) {
-               char *var = LstNode_Datum(ln);
+       for (ln = variables->first; ln != NULL; ln = ln->next) {
+               const char *var = ln->datum;
                const char *value;
                char *p1;
 
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/make.c       Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.146 2020/09/26 16:55:58 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.147 2020/09/26 17:15:20 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include    "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.146 2020/09/26 16:55:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.147 2020/09/26 17:15:20 rillig Exp $");
 
 static unsigned int checked = 1;/* Sequence # to detect recursion */
 static GNodeList *toBeMade;    /* The current fringe of the graph. These
@@ -1306,7 +1306,7 @@
     GNodeListNode *cln;
     GNode *cn;
 
-    for (cln = owln; (cn = LstNode_Datum(cln)) != wn; cln = LstNode_Next(cln)) {
+    for (cln = owln; (cn = cln->datum) != wn; cln = cln->next) {
        if (DEBUG(MAKE))
            fprintf(debug_file, ".WAIT: add dependency %s%s -> %s\n",
                    cn->name, cn->cohort_num, wn->name);
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/meta.c       Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.119 2020/09/24 07:53:32 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.120 2020/09/26 17:15:20 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1331,7 +1331,7 @@
                            do {
                                char *tp;
                                nln = Lst_FindFrom(missingFiles,
-                                                  LstNode_Next(missingNode),
+                                                  missingNode->next,
                                                   path_match, p);
                                tp = LstNode_Datum(missingNode);
                                Lst_Remove(missingFiles, missingNode);
@@ -1565,7 +1565,7 @@
                            oodate = TRUE;
                    }
                    free(cmd);
-                   cmdNode = LstNode_Next(cmdNode);
+                   cmdNode = cmdNode->next;
                }
            } else if (strcmp(buf, "CWD") == 0) {
                /*
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Sep 26 17:02:11 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Sep 26 17:15:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.168 2020/09/26 16:00:12 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.169 2020/09/26 17:15:20 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #include         "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.168 2020/09/26 16:00:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.169 2020/09/26 17:15:20 rillig Exp $");
 
 #define SUFF_DEBUG0(fmt) \
     if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt)
@@ -487,8 +487,7 @@
        if (srcLn == NULL) {
            srcLn = Lst_Find(sufflist, SuffSuffIsPrefix, str);
        } else {
-           srcLn = Lst_FindFrom(sufflist, LstNode_Next(srcLn),
-                                 SuffSuffIsPrefix, str);
+           srcLn = Lst_FindFrom(sufflist, srcLn->next, SuffSuffIsPrefix, str);
        }
        if (srcLn == NULL) {
            /*
@@ -1332,7 +1331,7 @@
            Lst_Append(gn->parents, pgn);
            pgn->unmade++;
            /* Expand wildcards on new node */
-           SuffExpandWildcards(LstNode_Prev(cln), pgn);
+           SuffExpandWildcards(cln->prev, pgn);
        }
        Lst_Free(members);
 
@@ -1503,8 +1502,8 @@
     /*
      * Deal with wildcards and variables in any acquired sources
      */
-    for (ln = ln != NULL ? LstNode_Next(ln) : NULL; ln != NULL; ln = nln) {
-       nln = LstNode_Next(ln);
+    for (ln = ln != NULL ? ln->next : NULL; ln != NULL; ln = nln) {
+       nln = ln->next;
        SuffExpandChildren(ln, tGn);
     }
 
@@ -1609,7 +1608,7 @@
      * that still contain variables or wildcards in their names.
      */
     for (ln = Lst_First(gn->children); ln != NULL; ln = nln) {
-       nln = LstNode_Next(ln);
+       nln = ln->next;
        SuffExpandChildren(ln, gn);
     }
 
@@ -1763,7 +1762,7 @@
                /*
                 * Search from this suffix's successor...
                 */
-               ln = LstNode_Next(ln);
+               ln = ln->next;
            }
        }
 
@@ -1839,7 +1838,7 @@
      * that still contain variables or wildcards in their names.
      */
     for (ln = Lst_First(gn->children); ln != NULL; ln = nln) {
-       nln = LstNode_Next(ln);
+       nln = ln->next;
        SuffExpandChildren(ln, gn);
     }
 
diff -r f116d357bde9 -r 7078bf109f3a usr.bin/make/targ.c



Home | Main Index | Thread Index | Old Index