diff options
author | harti <harti@FreeBSD.org> | 2004-12-16 16:14:16 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2004-12-16 16:14:16 +0000 |
commit | ce24622080c0eb3be79451dd08003d8e95ce7e29 (patch) | |
tree | fdf4034c35002c2f5a941b3dae513d763e63ce80 /usr.bin/make/dir.c | |
parent | c9d76864dd7b7d31e691edce2d40a35711cc3f7c (diff) | |
download | FreeBSD-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/dir.c')
-rw-r--r-- | usr.bin/make/dir.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index f269196..c353629 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -164,9 +164,11 @@ __FBSDID("$FreeBSD$"); * in a cache for when Dir_MTime was actually called. */ -Lst *dirSearchPath; /* main search path */ +/* main search path */ +Lst dirSearchPath = Lst_Initializer(dirSearchPath); -static Lst *openDirectories; /* the list of all open directories */ +/* the list of all open directories */ +static Lst openDirectories = Lst_Initializer(openDirectories); /* * Variables for gathering statistics on the efficiency of the hashing @@ -208,8 +210,6 @@ void Dir_Init(void) { - dirSearchPath = Lst_Init(); - openDirectories = Lst_Init(); Hash_InitTable(&mtimes, 0); } @@ -230,8 +230,8 @@ Dir_InitDot(void) { LstNode *ln; - Dir_AddDir(openDirectories, "."); - if ((ln = Lst_Last(openDirectories)) == NULL) + Dir_AddDir(&openDirectories, "."); + if ((ln = Lst_Last(&openDirectories)) == NULL) err(1, "cannot open current directory"); dot = Lst_Datum(ln); @@ -260,10 +260,10 @@ Dir_End(void) dot->refCount -= 1; Dir_Destroy(dot); - Dir_ClearPath(dirSearchPath); - Lst_Destroy(dirSearchPath, NOFREE); - Dir_ClearPath(openDirectories); - Lst_Destroy(openDirectories, NOFREE); + Dir_ClearPath(&dirSearchPath); + Lst_Destroy(&dirSearchPath, NOFREE); + Dir_ClearPath(&openDirectories); + Lst_Destroy(&openDirectories, NOFREE); Hash_DeleteTable(&mtimes); } @@ -611,14 +611,14 @@ Dir_Expand(char *word, Lst *path, Lst *expansions) char *dp = &dirpath[strlen(dirpath) - 1]; + Lst tp = Lst_Initializer(tp); if (*dp == '/') *dp = '\0'; - path = Lst_Init(); - Dir_AddDir(path, dirpath); - DirExpandInt(cp + 1, path, + Dir_AddDir(&tp, dirpath); + DirExpandInt(cp + 1, &tp, expansions); - Lst_Destroy(path, NOFREE); + Lst_Destroy(&tp, NOFREE); } } else { /* @@ -942,7 +942,7 @@ Dir_MTime(GNode *gn) return (Arch_MTime(gn)); else if (gn->path == NULL) - fullName = Dir_FindFile(gn->name, dirSearchPath); + fullName = Dir_FindFile(gn->name, &dirSearchPath); else fullName = gn->path; @@ -1000,7 +1000,7 @@ Dir_AddDir(Lst *path, char *name) DIR *d; /* for reading directory */ struct dirent *dp; /* entry in directory */ - ln = Lst_Find(openDirectories, name, DirFindName); + ln = Lst_Find(&openDirectories, name, DirFindName); if (ln != NULL) { p = Lst_Datum(ln); if (Lst_Member(path, p) == NULL) { @@ -1043,8 +1043,8 @@ Dir_AddDir(Lst *path, char *name) (Boolean *)NULL); } closedir(d); - Lst_AtEnd(openDirectories, p); - if (path != openDirectories) + Lst_AtEnd(&openDirectories, p); + if (path != &openDirectories) Lst_AtEnd(path, p); } DEBUGF(DIR, ("done\n")); @@ -1139,8 +1139,8 @@ Dir_Destroy(void *pp) if (p->refCount == 0) { LstNode *ln; - if ((ln = Lst_Member(openDirectories, p)) != NULL) - Lst_Remove(openDirectories, ln); + if ((ln = Lst_Member(&openDirectories, p)) != NULL) + Lst_Remove(&openDirectories, ln); Hash_DeleteTable(&p->files); free(p->name); @@ -1216,7 +1216,7 @@ Dir_PrintDirectories(void) (hits + bigmisses + nearmisses ? hits * 100 / (hits + bigmisses + nearmisses) : 0)); printf("# %-20s referenced\thits\n", "directory"); - for (ln = Lst_First(openDirectories); ln != NULL; ln = Lst_Succ(ln)) { + for (ln = Lst_First(&openDirectories); ln != NULL; ln = Lst_Succ(ln)) { p = Lst_Datum(ln); printf("# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits); } |