Module Name:    othersrc
Committed By:   dholland
Date:           Sat Mar 23 19:29:31 UTC 2013

Modified Files:
        othersrc/usr.bin/dholland-make2: dir.c

Log Message:
Remove another linked list.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 othersrc/usr.bin/dholland-make2/dir.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/usr.bin/dholland-make2/dir.c
diff -u othersrc/usr.bin/dholland-make2/dir.c:1.5 othersrc/usr.bin/dholland-make2/dir.c:1.6
--- othersrc/usr.bin/dholland-make2/dir.c:1.5	Tue Mar  5 03:32:08 2013
+++ othersrc/usr.bin/dholland-make2/dir.c	Sat Mar 23 19:29:30 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.5 2013/03/05 03:32:08 dholland Exp $	*/
+/*	$NetBSD: dir.c,v 1.6 2013/03/23 19:29:30 dholland Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -137,7 +137,7 @@
 #include "hash.h"
 #include "dir.h"
 
-__RCSID("$NetBSD: dir.c,v 1.5 2013/03/05 03:32:08 dholland Exp $");
+__RCSID("$NetBSD: dir.c,v 1.6 2013/03/23 19:29:30 dholland Exp $");
 
 /*
  *	A search path consists of a list of Path structures. A Path structure
@@ -209,9 +209,11 @@ __RCSID("$NetBSD: dir.c,v 1.5 2013/03/05
  *	in a cache for when Dir_MTime was actually called.
  */
 
-struct patharray dirSearchPath;	/* main search path */
+/* main search path */
+struct patharray dirSearchPath;
 
-static Lst   openDirectories;	/* the list of all open directories */
+/* all open directories */
+static struct patharray openDirectories;
 
 /*
  * Variables for gathering statistics on the efficiency of the hashing
@@ -258,7 +260,7 @@ void
 Dir_Init(const char *cdname)
 {
     patharray_init(&dirSearchPath);
-    openDirectories = Lst_Init(FALSE);
+    patharray_init(&openDirectories);
     Hash_InitTable(&mtimes, 0);
 
     Dir_InitCur(cdname);
@@ -313,11 +315,8 @@ void
 Dir_InitDot(void)
 {
     if (dot != NULL) {
-	LstNode ln;
-
 	/* Remove old entry from openDirectories, but do not destroy. */
-	ln = Lst_Member(openDirectories, dot);
-	(void)Lst_Remove(openDirectories, ln);
+	patharray_removeval(&openDirectories, dot);
     }
 
     dot = Dir_AddDir(NULL, ".");
@@ -359,10 +358,10 @@ Dir_End(void)
     dotLast->refCount -= 1;
     Dir_Destroy(dotLast);
     Dir_Destroy(dot);
-    Dir_ClearPath(dirSearchPath);
-    Lst_Destroy(dirSearchPath, NULL);
-    Dir_ClearPath(openDirectories);
-    Lst_Destroy(openDirectories, NULL);
+    Dir_ClearPath(&dirSearchPath);
+    patharray_cleanup(&dirSearchPath);
+    Dir_ClearPath(&openDirectories);
+    patharray_cleanup(&openDirectories);
     Hash_DeleteTable(&mtimes);
 #endif
 }
@@ -415,30 +414,9 @@ Dir_SetPATH(void)
     }
 }
 
-/*-
- *-----------------------------------------------------------------------
- * DirFindName --
- *	See if the Path structure describes the same directory as the
- *	given one by comparing their names. Called from Dir_AddDir via
- *	Lst_Find when searching the list of open directories.
- *
- * Input:
- *	p		Current name
- *	dname		Desired name
- *
- * Results:
- *	0 if it is the same. Non-zero otherwise
- *
- * Side Effects:
- *	None
- *-----------------------------------------------------------------------
+/*
+ * Look up a Path structure by name in an array of them.
  */
-static int
-DirFindName(const void *p, const void *dname)
-{
-    return (strcmp(((const Path *)p)->name, dname));
-}
-
 static Path *
 DirFind(const struct patharray *path, const char *name)
 {
@@ -1506,9 +1484,7 @@ Dir_MTime(GNode *gn, Boolean recheck)
 /*-
  *-----------------------------------------------------------------------
  * Dir_AddDir --
- *	Add the given name to the end of the given path. The order of
- *	the arguments is backwards so ParseDoDependency can do a
- *	Lst_ForEach of its list of paths...
+ *	Add the given name to the end of the given path.
  *
  * Input:
  *	path		the path to which the directory should be
@@ -1526,7 +1502,6 @@ Dir_MTime(GNode *gn, Boolean recheck)
 Path *
 Dir_AddDir(struct patharray *path, const char *name)
 {
-    LstNode       ln = NULL; /* node in case Path structure is found */
     Path	  *p;        /* pointer to new Path structure */
     DIR     	  *d;	      /* for reading directory */
     struct dirent *dp;	      /* entry in directory */
@@ -1542,12 +1517,9 @@ Dir_AddDir(struct patharray *path, const
 	}
     }
 
-    p = NULL;
+    p = (path == NULL) ? NULL : DirFind(&openDirectories, name);
 
-    if (path)
-	ln = Lst_Find(openDirectories, name, DirFindName);
-    if (ln != NULL) {
-	p = (Path *)Lst_Datum(ln);
+    if (p != NULL) {
 	if (path && !patharray_contains(path, p)) {
 	    p->refCount += 1;
 	    patharray_add(path, p, NULL);
@@ -1578,7 +1550,7 @@ Dir_AddDir(struct patharray *path, const
 		(void)Hash_CreateEntry(&p->files, dp->d_name, NULL);
 	    }
 	    (void)closedir(d);
-	    (void)Lst_AtEnd(openDirectories, p);
+	    patharray_add(&openDirectories, p, NULL);
 	    if (path != NULL)
 		patharray_add(path, p, NULL);
 	}
@@ -1677,11 +1649,7 @@ Dir_Destroy(Path *p)
     p->refCount -= 1;
 
     if (p->refCount == 0) {
-	LstNode	ln;
-
-	ln = Lst_Member(openDirectories, p);
-	(void)Lst_Remove(openDirectories, ln);
-
+	patharray_removeval(&openDirectories, p);
 	Hash_DeleteTable(&p->files);
 	free(p->name);
 	free(p);
@@ -1756,8 +1724,8 @@ Dir_Concat(struct patharray *path1, cons
 void
 Dir_PrintDirectories(void)
 {
-    LstNode	ln;
     Path	*p;
+    unsigned i, num;
 
     fprintf(debug_file, "#*** Directory Cache:\n");
     fprintf(debug_file, "# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
@@ -1765,12 +1733,11 @@ Dir_PrintDirectories(void)
 	      (hits+bigmisses+nearmisses ?
 	       hits * 100 / (hits + bigmisses + nearmisses) : 0));
     fprintf(debug_file, "# %-20s referenced\thits\n", "directory");
-    if (Lst_Open(openDirectories) == SUCCESS) {
-	while ((ln = Lst_Next(openDirectories)) != NULL) {
-	    p = (Path *)Lst_Datum(ln);
-	    fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits);
-	}
-	Lst_Close(openDirectories);
+    num = patharray_num(&openDirectories);
+    for (i=0; i<num; i++) {
+	p = patharray_get(&openDirectories, i);
+	fprintf(debug_file, "# %-20s %10d\t%4d\n",
+		p->name, p->refCount, p->hits);
     }
 }
 

Reply via email to