Module Name: src Committed By: rillig Date: Sun Mar 14 18:23:44 UTC 2021
Modified Files: src/usr.bin/make: var.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.872 -r1.873 src/usr.bin/make/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.872 src/usr.bin/make/var.c:1.873 --- src/usr.bin/make/var.c:1.872 Sun Mar 14 18:10:57 2021 +++ src/usr.bin/make/var.c Sun Mar 14 18:23:44 2021 @@ -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 @@ ApplyModifier_Hash(const char **pp, Appl 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 @@ ApplyModifier_Path(const char **pp, Appl (*pp)++; + if (!(st->expr->eflags & VARE_WANTRES)) + return AMR_OK; + Expr_Define(expr); gn = Targ_FindNode(expr->var->name.str); @@ -2700,6 +2704,9 @@ ApplyModifier_Range(const char **pp, App *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 @@ ApplyModifier_Quote(const char **pp, App 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 @@ ApplyModifier_ToSep(const char **pp, App { 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 @@ ApplyModifier_To(const char **pp, ApplyM 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 @@ ApplyModifier_WordFunc(const char **pp, 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 @@ ApplyModifier_Unique(const char **pp, Ap 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; }