diff options
| author | rillig <rillig@NetBSD.org> | 2020-08-28 04:59:17 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2020-08-28 04:59:17 +0000 |
| commit | 0fe719fa3d29ccc09f457f8aefa0fdc8b64fa203 (patch) | |
| tree | 938388a7e116065ad61a43868a1f7dca25ba081c /usr.bin/make/dir.c | |
| parent | fc1a2d633a49b04df019220529ae737840b3dad7 (diff) | |
make(1): clean up Dir_AddDir
Extract the null check for path to the top level. This has the
side-effect of only incrementing dotLast.refCount if that entry is
actually used.
Reduce the indentation of the code by returning early from the simple
branches.
Diffstat (limited to 'usr.bin/make/dir.c')
| -rw-r--r-- | usr.bin/make/dir.c | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index e82844d798f..6ee6786b1f4 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.119 2020/08/28 04:48:57 rillig Exp $ */ +/* $NetBSD: dir.c,v 1.120 2020/08/28 04:59:17 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: dir.c,v 1.119 2020/08/28 04:48:57 rillig Exp $"; +static char rcsid[] = "$NetBSD: dir.c,v 1.120 2020/08/28 04:59:17 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: dir.c,v 1.119 2020/08/28 04:48:57 rillig Exp $"); +__RCSID("$NetBSD: dir.c,v 1.120 2020/08/28 04:59:17 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -1564,57 +1564,54 @@ Dir_AddDir(Lst path, const char *name) DIR *d; /* for reading directory */ struct dirent *dp; /* entry in directory */ - if (strcmp(name, ".DOTLAST") == 0) { - ln = path != NULL ? Lst_Find(path, DirFindName, name) : NULL; + if (path != NULL && strcmp(name, ".DOTLAST") == 0) { + ln = Lst_Find(path, DirFindName, name); if (ln != NULL) return Lst_Datum(ln); - else { - /* XXX: It is wrong to increment the refCount if dotLast is not - * used afterwards. */ - dotLast->refCount += 1; - if (path != NULL) - Lst_Prepend(path, dotLast); - } + + dotLast->refCount++; + Lst_Prepend(path, dotLast); } - if (path) + if (path != NULL) ln = Lst_Find(openDirectories, DirFindName, name); if (ln != NULL) { p = Lst_Datum(ln); - if (path && Lst_Member(path, p) == NULL) { + if (Lst_Member(path, p) == NULL) { p->refCount += 1; Lst_Append(path, p); } - } else { - DIR_DEBUG1("Caching %s ...", name); + return p; + } + + DIR_DEBUG1("Caching %s ...", name); - if ((d = opendir(name)) != NULL) { - p = bmake_malloc(sizeof(Path)); - p->name = bmake_strdup(name); - p->hits = 0; - p->refCount = 1; - Hash_InitTable(&p->files, -1); + if ((d = opendir(name)) != NULL) { + p = bmake_malloc(sizeof(Path)); + p->name = bmake_strdup(name); + p->hits = 0; + p->refCount = 1; + Hash_InitTable(&p->files, -1); - while ((dp = readdir(d)) != NULL) { + while ((dp = readdir(d)) != NULL) { #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */ - /* - * The sun directory library doesn't check for a 0 inode - * (0-inode slots just take up space), so we have to do - * it ourselves. - */ - if (dp->d_fileno == 0) { - continue; - } -#endif /* sun && d_ino */ - (void)Hash_CreateEntry(&p->files, dp->d_name, NULL); + /* + * The sun directory library doesn't check for a 0 inode + * (0-inode slots just take up space), so we have to do + * it ourselves. + */ + if (dp->d_fileno == 0) { + continue; } - (void)closedir(d); - Lst_Append(openDirectories, p); - if (path != NULL) - Lst_Append(path, p); +#endif /* sun && d_ino */ + (void)Hash_CreateEntry(&p->files, dp->d_name, NULL); } - DIR_DEBUG0("done\n"); + (void)closedir(d); + Lst_Append(openDirectories, p); + if (path != NULL) + Lst_Append(path, p); } + DIR_DEBUG0("done\n"); return p; } |
