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: clean up 'explode'



details:   https://anonhg.NetBSD.org/src/rev/9c4f91f2e415
branches:  trunk
changeset: 1029212:9c4f91f2e415
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 27 20:59:59 2021 +0000

description:
make: clean up 'explode'

Breaking out of the first 'for' loop was unnecessarily complicated.  The
call to strlen was not necessary since f already pointed at the end of
the string.

No functional change.

diffstat:

 usr.bin/make/main.c |  33 ++++++++++++++-------------------
 1 files changed, 14 insertions(+), 19 deletions(-)

diffs (60 lines):

diff -r 0464fa6f82b8 -r 9c4f91f2e415 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Mon Dec 27 20:17:35 2021 +0000
+++ b/usr.bin/make/main.c       Mon Dec 27 20:59:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.550 2021/12/27 18:54:19 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.551 2021/12/27 20:59:59 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.550 2021/12/27 18:54:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.551 2021/12/27 20:59:59 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -153,29 +153,24 @@
 static char *
 explode(const char *flags)
 {
-       size_t len;
-       char *nf, *st;
-       const char *f;
+       char *exploded, *ep;
+       const char *p;
 
        if (flags == NULL)
                return NULL;
 
-       for (f = flags; *f != '\0'; f++)
-               if (!ch_isalpha(*f))
-                       break;
-
-       if (*f != '\0')
-               return bmake_strdup(flags);
+       for (p = flags; *p != '\0'; p++)
+               if (!ch_isalpha(*p))
+                       return bmake_strdup(flags);
 
-       len = strlen(flags);
-       st = nf = bmake_malloc(len * 3 + 1);
-       while (*flags != '\0') {
-               *nf++ = '-';
-               *nf++ = *flags++;
-               *nf++ = ' ';
+       exploded = bmake_malloc((size_t)(p - flags) * 3 + 1);
+       for (p = flags, ep = exploded; *p != '\0'; p++) {
+               *ep++ = '-';
+               *ep++ = *p;
+               *ep++ = ' ';
        }
-       *nf = '\0';
-       return st;
+       *ep = '\0';
+       return exploded;
 }
 
 MAKE_ATTR_DEAD static void



Home | Main Index | Thread Index | Old Index