Module Name: src
Committed By: rillig
Date: Sat Oct 24 10:17:21 UTC 2020
Modified Files:
src/usr.bin/make: meta.c
Log Message:
make(1): make Lst_RemoveIf simpler in meta_oodate
Using Lst_Find and Lst_FindFrom to implement Lst_RemoveIf was a bad
idea. It made the code much more complicated than necessary. There is
no predefined Lst_RemoveIf, but that can be implemented easily. By
inlining the list handling, path_match does not need void pointers
anymore.
Freeing the path from the missingFiles list had been implemented in a
surprisingly complicated way, intermangling it unnecessarily with the
list operations, even though these are completely independent.
To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/make/meta.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.128 src/usr.bin/make/meta.c:1.129
--- src/usr.bin/make/meta.c:1.128 Sat Oct 24 04:31:53 2020
+++ src/usr.bin/make/meta.c Sat Oct 24 10:17:21 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.128 2020/10/24 04:31:53 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.129 2020/10/24 10:17:21 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -961,10 +961,8 @@ prefix_match(void *p, void *q)
/* See if the path equals prefix or starts with "prefix/". */
static Boolean
-path_match(const void *p, const void *q)
+path_starts_with(const char *path, const char *prefix)
{
- const char *path = p;
- const char *prefix = q;
size_t n = strlen(prefix);
if (strncmp(path, prefix, n) != 0)
@@ -1315,22 +1313,16 @@ meta_oodate(GNode *gn, Boolean oodate)
DEQUOTE(move_target);
/* FALLTHROUGH */
case 'D': /* unlink */
- if (*p == '/' && !Lst_IsEmpty(missingFiles)) {
+ if (*p == '/') {
/* remove any missingFiles entries that match p */
- StringListNode *missingNode =
- Lst_Find(missingFiles, path_match, p);
- if (missingNode != NULL) {
- StringListNode *nln;
-
- do {
- char *tp;
- nln = Lst_FindFrom(missingFiles,
- missingNode->next,
- path_match, p);
- tp = missingNode->datum;
- Lst_Remove(missingFiles, missingNode);
- free(tp);
- } while ((missingNode = nln) != NULL);
+ StringListNode *ln = missingFiles->first;
+ while (ln != NULL) {
+ StringListNode *next = ln->next;
+ if (path_starts_with(ln->datum, p)) {
+ free(ln->datum);
+ Lst_Remove(missingFiles, ln);
+ }
+ ln = next;
}
}
if (buf[0] == 'M') {