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): use loops instead of Lst_ForEach for p...
details: https://anonhg.NetBSD.org/src/rev/908bd609a6a4
branches: trunk
changeset: 937994:908bd609a6a4
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 29 20:20:44 2020 +0000
description:
make(1): use loops instead of Lst_ForEach for propagating to cohorts
For one-liners, Lst_ForEach creates a lot of overhead, both at runtime
and for reading and understanding the code.
In this simple case where the structure of the traversed nodes is not
modified, a simple loop is enough. This avoids a lot of conversions to
void * and thus prevents type mistakes.
diffstat:
usr.bin/make/targ.c | 74 +++++++++++++++-------------------------------------
1 files changed, 21 insertions(+), 53 deletions(-)
diffs (110 lines):
diff -r 9c0c1a88c81a -r 908bd609a6a4 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c Sat Aug 29 20:08:08 2020 +0000
+++ b/usr.bin/make/targ.c Sat Aug 29 20:20:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: targ.c,v 1.77 2020/08/28 19:14:07 rillig Exp $ */
+/* $NetBSD: targ.c,v 1.78 2020/08/29 20:20:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.77 2020/08/28 19:14:07 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.78 2020/08/29 20:20:44 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: targ.c,v 1.77 2020/08/28 19:14:07 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.78 2020/08/29 20:20:44 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -147,8 +147,6 @@
#ifdef CLEANUP
static void TargFreeGN(void *);
#endif
-static int TargPropagateCohort(void *, void *);
-static int TargPropagateNode(void *, void *);
void
Targ_Init(void)
@@ -577,56 +575,26 @@
Suff_PrintAll();
}
-/* Propagate information from a single node to related nodes if appropriate.
- *
- * Information is propagated from this node to cohort nodes.
- *
- * If the node was defined with "::", then TargPropagateCohort() will be
- * called for each cohort node.
- *
- * Input:
- * gnp The node that we are processing.
+/* Propagate some type information to cohort nodes (those from the ::
+ * dependency operator).
*
- * Results:
- * Always returns 0, for the benefit of Lst_ForEach().
- */
-static int
-TargPropagateNode(void *gnp, void *junk MAKE_ATTR_UNUSED)
-{
- GNode *gn = (GNode *)gnp;
-
- if (gn->type & OP_DOUBLEDEP)
- Lst_ForEach(gn->cohorts, TargPropagateCohort, gnp);
- return 0;
-}
-
-/* Propagate some bits in the type mask from a node to a related cohort node.
- * cnp's type bitmask is modified to incorporate some of the bits from gnp's
- * type bitmask. (XXX need a better explanation.)
- *
- * Input:
- * cnp The node that we are processing.
- * gnp Another node that has cnp as a cohort.
- *
- * Results:
- * Always returns 0, for the benefit of Lst_ForEach().
- */
-static int
-TargPropagateCohort(void *cgnp, void *pgnp)
-{
- GNode *cgn = (GNode *)cgnp;
- GNode *pgn = (GNode *)pgnp;
-
- cgn->type |= pgn->type & ~OP_OPMASK;
- return 0;
-}
-
-/* Propagate information between related nodes. Should be called after the
- * makefiles are parsed but before any action is taken.
- *
- * Information is propagated between related nodes throughout the graph. */
+ * Should be called after the makefiles are parsed but before any action is
+ * taken. */
void
Targ_Propagate(void)
{
- Lst_ForEach(allTargets, TargPropagateNode, NULL);
+ LstNode pn, cn;
+
+ for (pn = Lst_First(allTargets); pn != NULL; pn = LstNode_Next(pn)) {
+ GNode *pgn = Lst_Datum(pn);
+
+ if (!(pgn->type & OP_DOUBLEDEP))
+ continue;
+
+ for (cn = Lst_First(pgn->cohorts); cn != NULL; cn = LstNode_Next(cn)) {
+ GNode *cgn = Lst_Datum(cn);
+
+ cgn->type |= pgn->type & ~OP_OPMASK;
+ }
+ }
}
Home |
Main Index |
Thread Index |
Old Index