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: don't evaluate several simple modifiers i...



details:   https://anonhg.NetBSD.org/src/rev/cb5bfb989aec
branches:  trunk
changeset: 960324:cb5bfb989aec
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 14 18:23:44 2021 +0000

description:
make: don't evaluate several simple modifiers in parse-only mode

This affects the modifiers ':E', ':H', ':P', ':Q', ':R', ':T', ':hash',
':q', ':range', ':tl', ':ts', ':tu', and ':u'.  All these modifiers are
side-effect free.

Skipping the evaluation for these modifiers is purely for code
consistency and performance.

No functional change.

diffstat:

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

diffs (111 lines):

diff -r e45502ae3382 -r cb5bfb989aec usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Mar 14 18:10:57 2021 +0000
+++ b/usr.bin/make/var.c        Sun Mar 14 18:23:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.872 2021/03/14 18:10:57 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.873 2021/03/14 18:23:44 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.872 2021/03/14 18:10:57 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.873 2021/03/14 18:23:44 rillig Exp $");
 
 typedef enum VarFlags {
        VFL_NONE        = 0,
@@ -2611,7 +2611,8 @@
                return AMR_UNKNOWN;
        *pp += 4;
 
-       Expr_SetValueOwn(st->expr, VarHash(st->expr->value.str));
+       if (st->expr->eflags & VARE_WANTRES)
+               Expr_SetValueOwn(st->expr, VarHash(st->expr->value.str));
 
        return AMR_OK;
 }
@@ -2626,6 +2627,9 @@
 
        (*pp)++;
 
+       if (!(st->expr->eflags & VARE_WANTRES))
+               return AMR_OK;
+
        Expr_Define(expr);
 
        gn = Targ_FindNode(expr->var->name.str);
@@ -2700,6 +2704,9 @@
                *pp = mod + 5;
        }
 
+       if (!(st->expr->eflags & VARE_WANTRES))
+               return AMR_OK;
+
        if (n == 0) {
                Words words = Str_Words(st->expr->value.str, FALSE);
                n = words.len;
@@ -2949,7 +2956,9 @@
                return AMR_UNKNOWN;
        (*pp)++;
 
-       Expr_SetValueOwn(st->expr, VarQuote(st->expr->value.str, quoteDollar));
+       if (st->expr->eflags & VARE_WANTRES)
+               Expr_SetValueOwn(st->expr,
+                   VarQuote(st->expr->value.str, quoteDollar));
 
        return AMR_OK;
 }
@@ -2967,6 +2976,13 @@
 {
        const char *sep = *pp + 2;
 
+       /*
+        * Even if VARE_WANTRES is not set, proceed as normal since there is
+        * neither any observable side effect nor a performance penalty.
+        * Checking for VARE_WANTRES for every single piece of code in here
+        * would make the code in this function too hard to read.
+        */
+
        /* ":ts<any><endc>" or ":ts<any>:" */
        if (sep[0] != st->endc && IsDelimiter(sep[1], st)) {
                *pp = sep + 1;
@@ -3089,13 +3105,15 @@
 
        if (mod[1] == 'u') {                            /* :tu */
                *pp = mod + 2;
-               Expr_SetValueOwn(expr, str_toupper(expr->value.str));
+               if (st->expr->eflags & VARE_WANTRES)
+                       Expr_SetValueOwn(expr, str_toupper(expr->value.str));
                return AMR_OK;
        }
 
        if (mod[1] == 'l') {                            /* :tl */
                *pp = mod + 2;
-               Expr_SetValueOwn(expr, str_tolower(expr->value.str));
+               if (st->expr->eflags & VARE_WANTRES)
+                       Expr_SetValueOwn(expr, str_tolower(expr->value.str));
                return AMR_OK;
        }
 
@@ -3464,7 +3482,8 @@
                return AMR_UNKNOWN;
        (*pp)++;
 
-       ModifyWords(st, modifyWord, NULL, st->oneBigWord);
+       if (st->expr->eflags & VARE_WANTRES)
+               ModifyWords(st, modifyWord, NULL, st->oneBigWord);
 
        return AMR_OK;
 }
@@ -3476,7 +3495,8 @@
                return AMR_UNKNOWN;
        (*pp)++;
 
-       Expr_SetValueOwn(st->expr, VarUniq(st->expr->value.str));
+       if (st->expr->eflags & VARE_WANTRES)
+               Expr_SetValueOwn(st->expr, VarUniq(st->expr->value.str));
 
        return AMR_OK;
 }



Home | Main Index | Thread Index | Old Index