Module Name: src
Committed By: rillig
Date: Sat Jun 11 08:06:32 UTC 2022
Modified Files:
src/usr.bin/make: str.c
Log Message:
make: condense Str_Match
The test for '\\' followed by '\0' was redundant since at that point,
*str is guaranteed to be not '\0', which takes the next 'return false'.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/make/str.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/str.c
diff -u src/usr.bin/make/str.c:1.91 src/usr.bin/make/str.c:1.92
--- src/usr.bin/make/str.c:1.91 Fri May 13 21:42:30 2022
+++ src/usr.bin/make/str.c Sat Jun 11 08:06:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.91 2022/05/13 21:42:30 rillig Exp $ */
+/* $NetBSD: str.c,v 1.92 2022/06/11 08:06:32 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
#include "make.h"
/* "@(#)str.c 5.8 (Berkeley) 6/1/90" */
-MAKE_RCSID("$NetBSD: str.c,v 1.91 2022/05/13 21:42:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.92 2022/06/11 08:06:32 rillig Exp $");
static HashTable interned_strings;
@@ -321,12 +321,8 @@ in_range(char e1, char c, char e2)
bool
Str_Match(const char *str, const char *pat)
{
- for (;;) {
- if (*pat == '\0')
- return *str == '\0';
-
- /* A '*' in the pattern matches any substring. */
- if (*pat == '*') {
+ for (; *pat != '\0'; pat++, str++) {
+ if (*pat == '*') { /* match any substring */
pat++;
while (*pat == '*')
pat++;
@@ -341,9 +337,8 @@ Str_Match(const char *str, const char *p
if (*str == '\0')
return false;
- /* A '?' in the pattern matches any single character. */
- if (*pat == '?')
- goto thisCharOK;
+ if (*pat == '?') /* match any single character */
+ continue;
/*
* A '[' in the pattern matches a character from a list.
@@ -387,26 +382,16 @@ Str_Match(const char *str, const char *p
pat++;
if (*pat == '\0')
pat--;
- goto thisCharOK;
+ continue;
}
- /*
- * A backslash in the pattern matches the character following
- * it exactly.
- */
- if (*pat == '\\') {
+ if (*pat == '\\') /* match the next character exactly */
pat++;
- if (*pat == '\0')
- return false;
- }
if (*pat != *str)
return false;
-
- thisCharOK:
- pat++;
- str++;
}
+ return *str == '\0';
}
void