summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/lst.lib
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/lst.lib
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/lst.lib')
-rw-r--r--usr.bin/make/lst.lib/lstConcat.c1
-rw-r--r--usr.bin/make/lst.lib/lstDestroy.c16
-rw-r--r--usr.bin/make/lst.lib/lstDupl.c30
-rw-r--r--usr.bin/make/lst.lib/lstInit.c76
4 files changed, 11 insertions, 112 deletions
diff --git a/usr.bin/make/lst.lib/lstConcat.c b/usr.bin/make/lst.lib/lstConcat.c
index a997fcb..e6bf54a 100644
--- a/usr.bin/make/lst.lib/lstConcat.c
+++ b/usr.bin/make/lst.lib/lstConcat.c
@@ -96,6 +96,7 @@ Lst_Concat(Lst *list1, Lst *list2, int flags)
list1->firstPtr = list2->firstPtr;
list1->lastPtr = list2->lastPtr;
+ Lst_Init(list2);
} else {
/*
* The loop simply goes through the entire
diff --git a/usr.bin/make/lst.lib/lstDestroy.c b/usr.bin/make/lst.lib/lstDestroy.c
index 15bac2d..39d5239 100644
--- a/usr.bin/make/lst.lib/lstDestroy.c
+++ b/usr.bin/make/lst.lib/lstDestroy.c
@@ -69,18 +69,9 @@ Lst_Destroy(Lst *list, FreeProc *freeProc)
{
LstNode *ln;
- if (!Lst_Valid(list)) {
- /*
- * Note the check to catch uninitialized static Lst's.
- * Gross, but useful.
- */
+ if (list->firstPtr == NULL)
return;
- }
- if (list->firstPtr == NULL) {
- free(list);
- return;
- }
if (freeProc != NOFREE) {
while ((ln = list->firstPtr) != NULL) {
list->firstPtr = ln->nextPtr;
@@ -90,9 +81,8 @@ Lst_Destroy(Lst *list, FreeProc *freeProc)
} else {
while ((ln = list->firstPtr) != NULL) {
list->firstPtr = ln->nextPtr;
- free(ln);
+ free(ln);
}
}
-
- free(list);
+ list->lastPtr = NULL;
}
diff --git a/usr.bin/make/lst.lib/lstDupl.c b/usr.bin/make/lst.lib/lstDupl.c
index 2596816..807cc19 100644
--- a/usr.bin/make/lst.lib/lstDupl.c
+++ b/usr.bin/make/lst.lib/lstDupl.c
@@ -56,40 +56,24 @@ __FBSDID("$FreeBSD$");
* Duplicate an entire list. If a function to copy a void * is
* given, the individual client elements will be duplicated as well.
*
- * Results:
- * The new Lst structure or NULL if failure.
- *
* Arguments:
- * l the list to duplicate
+ * dst the destination list (initialized)
+ * src the list to duplicate
* copyProc A function to duplicate each void
*
- * Side Effects:
- * A new list is created.
*-----------------------------------------------------------------------
*/
-Lst *
-Lst_Duplicate(Lst *list, DuplicateProc *copyProc)
+void
+Lst_Duplicate(Lst *dst, Lst *src, DuplicateProc *copyProc)
{
- Lst *nl;
LstNode *ln;
- if (!Lst_Valid(list)) {
- return (NULL);
- }
-
- nl = Lst_Init();
- if (nl == NULL) {
- return (NULL);
- }
-
- ln = list->firstPtr;
+ ln = src->firstPtr;
while (ln != NULL) {
if (copyProc != NOCOPY)
- Lst_AtEnd(nl, (*copyProc)(ln->datum));
+ Lst_AtEnd(dst, (*copyProc)(ln->datum));
else
- Lst_AtEnd(nl, ln->datum);
+ Lst_AtEnd(dst, ln->datum);
ln = ln->nextPtr;
}
-
- return (nl);
}
diff --git a/usr.bin/make/lst.lib/lstInit.c b/usr.bin/make/lst.lib/lstInit.c
deleted file mode 100644
index 7fc775d..0000000
--- a/usr.bin/make/lst.lib/lstInit.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 1988, 1989, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Adam de Boor.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)lstInit.c 8.1 (Berkeley) 6/6/93
- */
-
-#ifndef lint
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-#endif /* not lint */
-
-/*-
- * init.c --
- * Initialize a new linked list.
- */
-
-#include "make.h"
-#include "lst.h"
-
-/*-
- *-----------------------------------------------------------------------
- * Lst_Init --
- * Create and initialize a new list.
- *
- * Results:
- * The created list.
- *
- * Side Effects:
- * A list is created, what else?
- *
- *-----------------------------------------------------------------------
- */
-Lst *
-Lst_Init(void)
-{
- Lst *nList;
-
- nList = emalloc(sizeof(*nList));
-
- nList->firstPtr = NULL;
- nList->lastPtr = NULL;
-
- return (nList);
-}
OpenPOWER on IntegriCloud