summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/targ.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-12-16 16:14:16 +0000
committerharti <harti@FreeBSD.org>2004-12-16 16:14:16 +0000
commitce24622080c0eb3be79451dd08003d8e95ce7e29 (patch)
treefdf4034c35002c2f5a941b3dae513d763e63ce80 /usr.bin/make/targ.c
parentc9d76864dd7b7d31e691edce2d40a35711cc3f7c (diff)
downloadFreeBSD-src-ce24622080c0eb3be79451dd08003d8e95ce7e29.zip
FreeBSD-src-ce24622080c0eb3be79451dd08003d8e95ce7e29.tar.gz
Instead of dynamically allocating list heads allocated them statically
now that their size is only two pointers. This eliminates a lot of calls to Lst_Init and from there to malloc together with many calls to Lst_Destroy (in places where the list is obviously empty). This also reduces the chance to leave a list uninitilized so we can remove more NULL pointer checks and probably eliminates a couple of memory leaks.
Diffstat (limited to 'usr.bin/make/targ.c')
-rw-r--r--usr.bin/make/targ.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c
index 358399b..eff08ee 100644
--- a/usr.bin/make/targ.c
+++ b/usr.bin/make/targ.c
@@ -88,7 +88,9 @@ __FBSDID("$FreeBSD$");
#include "hash.h"
#include "dir.h"
-static Lst *allTargets; /* the list of all targets found so far */
+/* the list of all targets found so far */
+static Lst allTargets = Lst_Initializer(allTargets);
+
static Hash_Table targets; /* a hash table of same */
#define HTSIZE 191 /* initial size of hash table */
@@ -113,7 +115,6 @@ void
Targ_Init(void)
{
- allTargets = Lst_Init();
Hash_InitTable(&targets, HTSIZE);
}
@@ -133,7 +134,7 @@ void
Targ_End(void)
{
- Lst_Destroy(allTargets, NOFREE);
+ Lst_Destroy(&allTargets, NOFREE);
Hash_DeleteTable(&targets);
}
@@ -169,14 +170,14 @@ Targ_NewGN(char *name)
gn->childMade = FALSE;
gn->order = 0;
gn->mtime = gn->cmtime = 0;
- gn->iParents = Lst_Init();
- gn->cohorts = Lst_Init();
- gn->parents = Lst_Init();
- gn->children = Lst_Init();
- gn->successors = Lst_Init();
- gn->preds = Lst_Init();
- gn->context = Lst_Init();
- gn->commands = Lst_Init();
+ Lst_Init(&gn->iParents);
+ Lst_Init(&gn->cohorts);
+ Lst_Init(&gn->parents);
+ Lst_Init(&gn->children);
+ Lst_Init(&gn->successors);
+ Lst_Init(&gn->preds);
+ Lst_Init(&gn->context);
+ Lst_Init(&gn->commands);
gn->suffix = NULL;
return (gn);
@@ -209,7 +210,7 @@ Targ_FindNode(char *name, int flags)
if (isNew) {
gn = Targ_NewGN(name);
Hash_SetValue (he, gn);
- Lst_AtEnd(allTargets, gn);
+ Lst_AtEnd(&allTargets, gn);
}
} else {
he = Hash_FindEntry(&targets, name);
@@ -237,16 +238,13 @@ Targ_FindNode(char *name, int flags)
* an error message will be printed for each name which can't be found.
* -----------------------------------------------------------------------
*/
-Lst *
-Targ_FindList(Lst *names, int flags)
+void
+Targ_FindList(Lst *nodes, Lst *names, int flags)
{
- Lst *nodes; /* result list */
LstNode *ln; /* name list element */
GNode *gn; /* node in tLn */
char *name;
- nodes = Lst_Init();
-
for (ln = Lst_First(names); ln != NULL; ln = Lst_Succ(ln)) {
name = Lst_Datum(ln);
gn = Targ_FindNode(name, flags);
@@ -258,13 +256,12 @@ Targ_FindList(Lst *names, int flags)
*/
Lst_AtEnd(nodes, gn);
if (gn->type & OP_DOUBLEDEP) {
- Lst_Concat(nodes, gn->cohorts, LST_CONCNEW);
+ Lst_Concat(nodes, &gn->cohorts, LST_CONCNEW);
}
} else if (flags == TARG_NOCREATE) {
Error("\"%s\" -- target unknown.", name);
}
}
- return (nodes);
}
/*-
@@ -501,15 +498,15 @@ TargPrintNode(void *gnp, void *passp)
printf("# unmade\n");
}
}
- if (!Lst_IsEmpty (gn->iParents)) {
+ if (!Lst_IsEmpty(&gn->iParents)) {
printf("# implicit parents: ");
- Lst_ForEach(gn->iParents, TargPrintName, (void *)NULL);
+ Lst_ForEach(&gn->iParents, TargPrintName, (void *)NULL);
fputc('\n', stdout);
}
}
- if (!Lst_IsEmpty (gn->parents)) {
+ if (!Lst_IsEmpty(&gn->parents)) {
printf("# parents: ");
- Lst_ForEach(gn->parents, TargPrintName, (void *)NULL);
+ Lst_ForEach(&gn->parents, TargPrintName, (void *)NULL);
fputc('\n', stdout);
}
@@ -525,12 +522,12 @@ TargPrintNode(void *gnp, void *passp)
break;
}
Targ_PrintType(gn->type);
- Lst_ForEach(gn->children, TargPrintName, (void *)NULL);
+ Lst_ForEach(&gn->children, TargPrintName, (void *)NULL);
fputc('\n', stdout);
- Lst_ForEach(gn->commands, Targ_PrintCmd, (void *)NULL);
+ Lst_ForEach(&gn->commands, Targ_PrintCmd, (void *)NULL);
printf("\n\n");
if (gn->type & OP_DOUBLEDEP) {
- Lst_ForEach(gn->cohorts, TargPrintNode, &pass);
+ Lst_ForEach(&gn->cohorts, TargPrintNode, &pass);
}
}
return (0);
@@ -577,10 +574,10 @@ Targ_PrintGraph(int pass)
{
printf("#*** Input graph:\n");
- Lst_ForEach(allTargets, TargPrintNode, &pass);
+ Lst_ForEach(&allTargets, TargPrintNode, &pass);
printf("\n\n");
printf("#\n# Files that are only sources:\n");
- Lst_ForEach(allTargets, TargPrintOnlySrc, (void *)NULL);
+ Lst_ForEach(&allTargets, TargPrintOnlySrc, (void *)NULL);
printf("#*** Global Variables:\n");
Var_Dump(VAR_GLOBAL);
printf("#*** Command-line Variables:\n");
OpenPOWER on IntegriCloud