Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): make Lst_RemoveIf simpler in meta_oodate
details: https://anonhg.NetBSD.org/src/rev/4e6f9add2f25
branches: trunk
changeset: 941576:4e6f9add2f25
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 24 10:17:21 2020 +0000
description:
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.
diffstat:
usr.bin/make/meta.c | 30 +++++++++++-------------------
1 files changed, 11 insertions(+), 19 deletions(-)
diffs (53 lines):
diff -r 2d3fc3d41e73 -r 4e6f9add2f25 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c Sat Oct 24 09:28:50 2020 +0000
+++ b/usr.bin/make/meta.c Sat Oct 24 10:17:21 2020 +0000
@@ -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 @@
/* 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 @@
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') {
Home |
Main Index |
Thread Index |
Old Index