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 simple Lst getters



details:   https://anonhg.NetBSD.org/src/rev/d0a23d63b222
branches:  trunk
changeset: 941156:d0a23d63b222
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Oct 19 21:57:37 2020 +0000

description:
make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access.  Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.

diffstat:

 usr.bin/make/arch.c  |   6 +++---
 usr.bin/make/dir.c   |   6 +++---
 usr.bin/make/lst.c   |   6 +++---
 usr.bin/make/lst.h   |  12 ++----------
 usr.bin/make/main.c  |   8 ++++----
 usr.bin/make/make.c  |  16 ++++++++--------
 usr.bin/make/meta.c  |  10 +++++-----
 usr.bin/make/parse.c |   6 +++---
 usr.bin/make/suff.c  |  40 ++++++++++++++++++++--------------------
 9 files changed, 51 insertions(+), 59 deletions(-)

diffs (truncated from 465 to 300 lines):

diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/arch.c       Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.136 2020/10/18 13:02:10 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.137 2020/10/19 21:57:37 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.136 2020/10/18 13:02:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.137 2020/10/19 21:57:37 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -468,7 +468,7 @@
     if (ln != NULL) {
        struct ar_hdr *hdr;
 
-       ar = LstNode_Datum(ln);
+       ar = ln->datum;
        hdr = Hash_FindValue(&ar->members, member);
        if (hdr != NULL)
            return hdr;
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/dir.c        Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.170 2020/10/18 17:19:54 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.171 2020/10/19 21:57:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -135,7 +135,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.170 2020/10/18 17:19:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.171 2020/10/19 21:57:37 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -1510,7 +1510,7 @@
     if (path != NULL && strcmp(name, ".DOTLAST") == 0) {
        SearchPathNode *ln = Lst_Find(path, DirFindName, name);
        if (ln != NULL)
-           return LstNode_Datum(ln);
+           return ln->datum;
 
        dotLast->refCount++;
        Lst_Prepend(path, dotLast);
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/lst.c        Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.78 2020/10/19 21:41:31 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.79 2020/10/19 21:57:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.78 2020/10/19 21:41:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.79 2020/10/19 21:57:37 rillig Exp $");
 
 /* Allocate and initialize a list node.
  *
@@ -268,7 +268,7 @@
 ListNode *
 Lst_Find(List *list, LstFindProc match, const void *matchArgs)
 {
-    return Lst_FindFrom(list, Lst_First(list), match, matchArgs);
+    return Lst_FindFrom(list, list->first, match, matchArgs);
 }
 
 /* Return the first node from the list, starting at the given node, for which
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/lst.h        Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.73 2020/10/19 21:41:31 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.74 2020/10/19 21:57:37 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -145,12 +145,7 @@
 
 static inline MAKE_ATTR_UNUSED Boolean
 Lst_IsEmpty(List *list) { return list->first == NULL; }
-/* Return the first node of the list, or NULL if the list is empty. */
-static inline MAKE_ATTR_UNUSED ListNode *
-Lst_First(List *list) { return list->first; }
-/* Return the last node of the list, or NULL if the list is empty. */
-static inline MAKE_ATTR_UNUSED ListNode *
-Lst_Last(List *list) { return list->last; }
+
 /* Find the first node for which the function returns TRUE, or NULL. */
 ListNode *Lst_Find(List *, LstFindProc, const void *);
 /* Find the first node for which the function returns TRUE, or NULL.
@@ -175,9 +170,6 @@
 
 /* Node-specific functions */
 
-/* Return the datum of the node. Usually not NULL. */
-static inline MAKE_ATTR_UNUSED void *
-LstNode_Datum(ListNode *node) { return node->datum; }
 /* Replace the value of the node. */
 void LstNode_Set(ListNode *, void *);
 /* Set the value of the node to NULL. Having NULL in a list is unusual. */
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/main.c       Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.378 2020/10/18 13:02:10 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.379 2020/10/19 21:57:37 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.378 2020/10/18 13:02:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.379 2020/10/19 21:57:37 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -1370,7 +1370,7 @@
                ln = Lst_Find(sysMkPath, ReadMakefileSucceeded, NULL);
                if (ln == NULL)
                        Fatal("%s: cannot open %s.", progname,
-                           (char *)LstNode_Datum(Lst_First(sysMkPath)));
+                           (char *)sysMkPath->first->datum);
        }
 
        if (!Lst_IsEmpty(makefiles)) {
@@ -1379,7 +1379,7 @@
                ln = Lst_Find(makefiles, ReadMakefileFailed, NULL);
                if (ln != NULL)
                        Fatal("%s: cannot open %s.", progname,
-                           (char *)LstNode_Datum(ln));
+                           (char *)ln->datum);
        } else {
                (void)Var_Subst("${" MAKEFILE_PREFERENCE "}",
                    VAR_CMD, VARE_WANTRES, &p1);
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/make.c       Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.164 2020/10/19 19:55:25 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.165 2020/10/19 21:57:37 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.164 2020/10/19 19:55:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.165 2020/10/19 21:57:37 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -622,12 +622,12 @@
     parents = centurion->parents;
 
     /* If this was a .ORDER node, schedule the RHS */
-    Lst_ForEachUntil(centurion->order_succ, MakeBuildParent, Lst_First(toBeMade));
+    Lst_ForEachUntil(centurion->order_succ, MakeBuildParent, toBeMade->first);
 
     /* Now mark all the parents as having one less unmade child */
     Lst_Open(parents);
     while ((ln = Lst_Next(parents)) != NULL) {
-       pgn = LstNode_Datum(ln);
+       pgn = ln->datum;
        if (DEBUG(MAKE))
            debug_printf("inspect parent %s%s: flags %x, "
                         "type %x, made %d, unmade %d ",
@@ -723,7 +723,7 @@
        const char *cpref = Var_Value(PREFIX, cgn, &p1);
 
        while ((ln = Lst_Next(cgn->implicitParents)) != NULL) {
-           pgn = LstNode_Datum(ln);
+           pgn = ln->datum;
            if (pgn->flags & REMAKE) {
                Var_Set(IMPSRC, cname, pgn);
                if (cpref != NULL)
@@ -961,7 +961,7 @@
             * just before the current first element.
             */
            gn->made = DEFERRED;
-           Lst_ForEachUntil(gn->children, MakeBuildChild, Lst_First(toBeMade));
+           Lst_ForEachUntil(gn->children, MakeBuildChild, toBeMade->first);
            /* and drop this node on the floor */
            DEBUG2(MAKE, "dropped %s%s\n", gn->name, gn->cohort_num);
            continue;
@@ -1240,10 +1240,10 @@
        if (pgn->type & OP_DOUBLEDEP)
            Lst_PrependAll(examine, pgn->cohorts);
 
-       owln = Lst_First(pgn->children);
+       owln = pgn->children->first;
        Lst_Open(pgn->children);
        for (; (ln = Lst_Next(pgn->children)) != NULL; ) {
-           GNode *cgn = LstNode_Datum(ln);
+           GNode *cgn = ln->datum;
            if (cgn->type & OP_WAIT) {
                add_wait_dependency(owln, cgn);
                owln = ln;
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/meta.c       Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.126 2020/10/19 20:41:53 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.127 2020/10/19 21:57:37 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1150,7 +1150,7 @@
        /* we want to track all the .meta we read */
        Var_Append(".MAKE.META.FILES", fname, VAR_GLOBAL);
 
-       cmdNode = Lst_First(gn->commands);
+       cmdNode = gn->commands->first;
        while (!oodate && (x = fgetLine(&buf, &bufsz, 0, fp)) > 0) {
            lineno++;
            if (buf[x - 1] == '\n')
@@ -1327,7 +1327,7 @@
                                nln = Lst_FindFrom(missingFiles,
                                                   missingNode->next,
                                                   path_match, p);
-                               tp = LstNode_Datum(missingNode);
+                               tp = missingNode->datum;
                                Lst_Remove(missingFiles, missingNode);
                                free(tp);
                            } while ((missingNode = nln) != NULL);
@@ -1502,7 +1502,7 @@
                           fname, lineno);
                    oodate = TRUE;
                } else {
-                   char *cmd = LstNode_Datum(cmdNode);
+                   char *cmd = cmdNode->datum;
                    Boolean hasOODATE = FALSE;
 
                    if (strstr(cmd, "$?"))
@@ -1579,7 +1579,7 @@
        fclose(fp);
        if (!Lst_IsEmpty(missingFiles)) {
            DEBUG2(META, "%s: missing files: %s...\n",
-                       fname, (char *)LstNode_Datum(Lst_First(missingFiles)));
+                  fname, (char *)missingFiles->first->datum);
            oodate = TRUE;
        }
        if (!oodate && !have_filemon && filemonMissing) {
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/parse.c      Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.393 2020/10/19 20:55:30 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.394 2020/10/19 21:57:37 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.393 2020/10/19 20:55:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.394 2020/10/19 21:57:37 rillig Exp $");
 
 /* types and constants */
 
@@ -762,7 +762,7 @@
 LinkSource(GNode *pgn, GNode *cgn, Boolean isSpecial)
 {
     if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts))
-       pgn = LstNode_Datum(Lst_Last(pgn->cohorts));
+       pgn = pgn->cohorts->last->datum;
 
     Lst_Append(pgn->children, cgn);
     pgn->unmade++;
diff -r 718cfb4319e6 -r d0a23d63b222 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Mon Oct 19 21:46:15 2020 +0000
+++ b/usr.bin/make/suff.c       Mon Oct 19 21:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.194 2020/10/19 21:38:10 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.195 2020/10/19 21:57:37 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -129,7 +129,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.194 2020/10/19 21:38:10 rillig Exp $");



Home | Main Index | Thread Index | Old Index