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: uncompress code in ApplyModifier_Unique



details:   https://anonhg.NetBSD.org/src/rev/119cfabdd24d
branches:  trunk
changeset: 379417:119cfabdd24d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 30 20:41:34 2021 +0000

description:
make: uncompress code in ApplyModifier_Unique

The algorithm is easier to understand when each line of code only
focuses on a single topic.

No change to the resulting binary, except for line numbers in assertion
messages.

diffstat:

 usr.bin/make/var.c |  21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diffs (42 lines):

diff -r b0e85b5f356e -r 119cfabdd24d usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun May 30 20:31:03 2021 +0000
+++ b/usr.bin/make/var.c        Sun May 30 20:41:34 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.931 2021/05/30 20:31:03 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.932 2021/05/30 20:41:34 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.931 2021/05/30 20:31:03 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.932 2021/05/30 20:41:34 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3559,12 +3559,17 @@ ApplyModifier_Unique(const char **pp, Mo
        words = Str_Words(ch->expr->value.str, false);
 
        if (words.len > 1) {
-               size_t i, j;
-               for (j = 0, i = 1; i < words.len; i++)
-                       if (strcmp(words.words[i], words.words[j]) != 0 &&
-                           (++j != i))
-                               words.words[j] = words.words[i];
-               words.len = j + 1;
+               size_t si, di;
+
+               di = 0;
+               for (si = 1; si < words.len; si++) {
+                       if (strcmp(words.words[si], words.words[di]) != 0) {
+                               di++;
+                               if (di != si)
+                                       words.words[di] = words.words[si];
+                       }
+               }
+               words.len = di + 1;
        }
 
        Expr_SetValueOwn(ch->expr, Words_JoinFree(words));



Home | Main Index | Thread Index | Old Index