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: condense Str_Match



details:   https://anonhg.NetBSD.org/src/rev/ea1d9f04d602
branches:  trunk
changeset: 366724:ea1d9f04d602
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 11 08:06:32 2022 +0000

description:
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.

diffstat:

 usr.bin/make/str.c |  33 +++++++++------------------------
 1 files changed, 9 insertions(+), 24 deletions(-)

diffs (75 lines):

diff -r 0098f6f0f5d2 -r ea1d9f04d602 usr.bin/make/str.c
--- a/usr.bin/make/str.c        Sat Jun 11 07:54:25 2022 +0000
+++ b/usr.bin/make/str.c        Sat Jun 11 08:06:32 2022 +0000
@@ -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 @@
 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 @@
                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 @@
                                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



Home | Main Index | Thread Index | Old Index