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: merge duplicate code in ApplyModifier_Rem...



details:   https://anonhg.NetBSD.org/src/rev/cee300a8d50f
branches:  trunk
changeset: 953630:cee300a8d50f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 14 17:34:50 2021 +0000

description:
make: merge duplicate code in ApplyModifier_Remember

This way, parsing and evaluating the modifier is only written once in
the code.  The downside is that the variable name is allocated even if
VARE_WANTRES is not set, but since this modifier is so obscure and
seldom used this doesn't matter in practice.

diffstat:

 usr.bin/make/var.c |  22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diffs (56 lines):

diff -r 267b2dd728b6 -r cee300a8d50f usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Mar 14 17:27:27 2021 +0000
+++ b/usr.bin/make/var.c        Sun Mar 14 17:34:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.867 2021/03/14 17:27:27 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.868 2021/03/14 17:34:50 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.867 2021/03/14 17:27:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.868 2021/03/14 17:34:50 rillig Exp $");
 
 typedef enum VarFlags {
        VFL_NONE        = 0,
@@ -3418,10 +3418,12 @@
 {
        Expr *expr = st->expr;
        const char *mod = *pp;
+       FStr name;
 
        if (!ModMatchEq(mod, "_", st))
                return AMR_UNKNOWN;
 
+       name = FStr_InitRefer("_");
        if (mod[1] == '=') {
                /*
                 * XXX: This ad-hoc call to strcspn deviates from the usual
@@ -3430,18 +3432,14 @@
                 */
                size_t n = strcspn(mod + 2, ":)}");
                *pp = mod + 2 + n;
-
-               if (expr->eflags & VARE_WANTRES) {
-                       char *name = bmake_strldup(mod + 2, n);
-                       Var_Set(expr->scope, name, expr->value.str);
-                       free(name);
-               }
-       } else {
+               name = FStr_InitOwn(bmake_strldup(mod + 2, n));
+       } else
                *pp = mod + 1;
 
-               if (expr->eflags & VARE_WANTRES)
-                       Var_Set(expr->scope, "_", expr->value.str);
-       }
+       if (expr->eflags & VARE_WANTRES)
+               Var_Set(expr->scope, name.str, expr->value.str);
+       FStr_Done(&name);
+
        return AMR_OK;
 }
 



Home | Main Index | Thread Index | Old Index