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): remove pointer indirection from GNode....



details:   https://anonhg.NetBSD.org/src/rev/62e3f3cde761
branches:  trunk
changeset: 946467:62e3f3cde761
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 28 18:55:52 2020 +0000

description:
make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations.  No noticeable effect on the
performance though.

diffstat:

 usr.bin/make/compat.c |  10 +++++-----
 usr.bin/make/cond.c   |   6 +++---
 usr.bin/make/job.c    |  14 +++++++-------
 usr.bin/make/lst.c    |  19 +++++++++++--------
 usr.bin/make/lst.h    |  12 +++++++++++-
 usr.bin/make/main.c   |   6 +++---
 usr.bin/make/make.c   |  10 +++++-----
 usr.bin/make/make.h   |   4 ++--
 usr.bin/make/meta.c   |  10 +++++-----
 usr.bin/make/parse.c  |   8 ++++----
 usr.bin/make/suff.c   |  14 +++++++-------
 usr.bin/make/targ.c   |  10 +++++-----
 12 files changed, 68 insertions(+), 55 deletions(-)

diffs (truncated from 481 to 300 lines):

diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/compat.c     Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.192 2020/11/24 19:04:42 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.193 2020/11/28 18:55:52 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.192 2020/11/24 19:04:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.193 2020/11/28 18:55:52 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -218,7 +218,7 @@
         * for delayed commands, run in parallel mode, using the same shell
         * command line more than once; see JobPrintCommand.
         * TODO: write a unit-test to protect against this potential bug. */
-       cmdNode = Lst_FindDatum(gn->commands, cmd);
+       cmdNode = Lst_FindDatum(&gn->commands, cmd);
        (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
        /* TODO: handle errors */
 
@@ -232,7 +232,7 @@
        if (gn->type & OP_SAVE_CMDS) {
                GNode *endNode = Targ_GetEndNode();
                if (gn != endNode) {
-                       Lst_Append(endNode->commands, cmdStart);
+                       Lst_Append(&endNode->commands, cmdStart);
                        return 0;
                }
        }
@@ -449,7 +449,7 @@
 {
        StringListNode *ln;
 
-       for (ln = gn->commands->first; ln != NULL; ln = ln->next) {
+       for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
                const char *cmd = ln->datum;
                if (Compat_RunCommand(cmd, gn) != 0)
                        break;
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.217 2020/11/23 20:52:59 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.218 2020/11/28 18:55:52 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.217 2020/11/23 20:52:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.218 2020/11/28 18:55:52 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -335,7 +335,7 @@
 FuncCommands(size_t argLen MAKE_ATTR_UNUSED, const char *arg)
 {
        GNode *gn = Targ_FindNode(arg);
-       return gn != NULL && GNode_IsTarget(gn) && !Lst_IsEmpty(gn->commands);
+       return gn != NULL && GNode_IsTarget(gn) && !Lst_IsEmpty(&gn->commands);
 }
 
 /*
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/job.c        Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.331 2020/11/28 08:40:05 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.332 2020/11/28 18:55:52 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.331 2020/11/28 08:40:05 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.332 2020/11/28 18:55:52 rillig Exp $");
 
 /* A shell defines how the commands are run.  All commands for a target are
  * written into a single file, which is then given to the shell to execute
@@ -902,7 +902,7 @@
 {
     StringListNode *ln;
 
-    for (ln = job->node->commands->first; ln != NULL; ln = ln->next) {
+    for (ln = job->node->commands.first; ln != NULL; ln = ln->next) {
        const char *cmd = ln->datum;
 
        if (strcmp(cmd, "...") == 0) {
@@ -929,7 +929,7 @@
         * expand the other variables as well; see deptgt-end.mk. */
        (void)Var_Subst(cmd, job->node, VARE_WANTRES, &expanded_cmd);
        /* TODO: handle errors */
-       Lst_Append(Targ_GetEndNode()->commands, expanded_cmd);
+       Lst_Append(&Targ_GetEndNode()->commands, expanded_cmd);
     }
 }
 
@@ -1175,7 +1175,7 @@
 {
     if (GNode_IsTarget(gn))
        return TRUE;
-    if (!Lst_IsEmpty(gn->commands))
+    if (!Lst_IsEmpty(&gn->commands))
        return TRUE;
     if ((gn->type & OP_LIB) && !Lst_IsEmpty(gn->children))
        return TRUE;
@@ -1184,7 +1184,7 @@
      * No commands. Look for .DEFAULT rule from which we might infer
      * commands.
      */
-    if (defaultNode != NULL && !Lst_IsEmpty(defaultNode->commands) &&
+    if (defaultNode != NULL && !Lst_IsEmpty(&defaultNode->commands) &&
        !(gn->type & OP_SPECIAL)) {
        /*
         * The traditional Make only looks for a .DEFAULT if the node was
@@ -2451,7 +2451,7 @@
 Job_Finish(void)
 {
     GNode *endNode = Targ_GetEndNode();
-    if (!Lst_IsEmpty(endNode->commands) || !Lst_IsEmpty(endNode->children)) {
+    if (!Lst_IsEmpty(&endNode->commands) || !Lst_IsEmpty(endNode->children)) {
        if (job_errors != 0) {
            Error("Errors reported so .END ignored");
        } else {
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.94 2020/11/27 08:07:26 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.95 2020/11/28 18:55:52 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.94 2020/11/27 08:07:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.95 2020/11/28 18:55:52 rillig Exp $");
 
 static ListNode *
 LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -53,16 +53,12 @@
 Lst_New(void)
 {
        List *list = bmake_malloc(sizeof *list);
-
-       list->first = NULL;
-       list->last = NULL;
-
+       Lst_Init(list);
        return list;
 }
 
-/* Free a list and all its nodes. The node data are not freed though. */
 void
-Lst_Free(List *list)
+Lst_Done(List *list)
 {
        ListNode *ln, *next;
 
@@ -70,7 +66,14 @@
                next = ln->next;
                free(ln);
        }
+}
 
+/* Free a list and all its nodes. The node data are not freed though. */
+void
+Lst_Free(List *list)
+{
+
+       Lst_Done(list);
        free(list);
 }
 
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.87 2020/11/27 08:07:26 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.88 2020/11/28 18:55:52 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -109,11 +109,21 @@
 
 /* Create a new list. */
 List *Lst_New(void);
+/* Free the list nodes, but not the list itself. */
+void Lst_Done(List *);
 /* Free the list, leaving the node data unmodified. */
 void Lst_Free(List *);
 /* Free the list, freeing the node data using the given function. */
 void Lst_Destroy(List *, LstFreeProc);
 
+/* Initialize a list, without memory allocation. */
+MAKE_INLINE void
+Lst_Init(List *list)
+{
+    list->first = NULL;
+    list->last = NULL;
+}
+
 /* Get information about a list */
 
 MAKE_INLINE Boolean
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/main.c       Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.482 2020/11/28 10:00:25 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.483 2020/11/28 18:55:52 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.482 2020/11/28 10:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.483 2020/11/28 18:55:52 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -2093,7 +2093,7 @@
        Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL);
        Var_Delete(".ERROR_CMD", VAR_GLOBAL);
 
-       for (ln = gn->commands->first; ln != NULL; ln = ln->next) {
+       for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
                const char *cmd = ln->datum;
 
                if (cmd == NULL)
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/make.c       Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.218 2020/11/27 08:07:26 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.219 2020/11/28 18:55:52 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -102,7 +102,7 @@
 #include "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.218 2020/11/27 08:07:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.219 2020/11/28 18:55:52 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked_seqno = 1;
@@ -376,13 +376,13 @@
     }
 #endif
 
-    if ((cgn->type & (OP_USE | OP_USEBEFORE)) || Lst_IsEmpty(pgn->commands)) {
+    if ((cgn->type & (OP_USE | OP_USEBEFORE)) || Lst_IsEmpty(&pgn->commands)) {
        if (cgn->type & OP_USEBEFORE) {
            /* .USEBEFORE */
-           Lst_PrependAll(pgn->commands, cgn->commands);
+           Lst_PrependAll(&pgn->commands, &cgn->commands);
        } else {
            /* .USE, or target has no commands */
-           Lst_AppendAll(pgn->commands, cgn->commands);
+           Lst_AppendAll(&pgn->commands, &cgn->commands);
        }
     }
 
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Nov 28 16:36:19 2020 +0000
+++ b/usr.bin/make/make.h       Sat Nov 28 18:55:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.220 2020/11/28 09:45:01 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.221 2020/11/28 18:55:52 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -421,7 +421,7 @@
        HashTable /* of Var pointer */ vars;
 
        /* The commands to be given to a shell to create this target. */
-       StringList *commands;
+       StringList commands;
 
        /* Suffix for the node (determined by Suff_FindDeps and opaque to
         * everyone but the Suff module) */
diff -r 9a64cdfe8896 -r 62e3f3cde761 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sat Nov 28 16:36:19 2020 +0000



Home | Main Index | Thread Index | Old Index