Sun Mar 14 17:38:24 2021 UTC ()
make: eliminate common subexpression in ApplyModifier_Remember

No functional change.


(rillig)
diff -r1.868 -r1.869 src/usr.bin/make/var.c

cvs diff -r1.868 -r1.869 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2021/03/14 17:34:50 1.868
+++ src/usr.bin/make/var.c 2021/03/14 17:38:24 1.869
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.868 2021/03/14 17:34:50 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.869 2021/03/14 17:38:24 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -130,27 +130,27 @@ @@ -130,27 +130,27 @@
130#include <regex.h> 130#include <regex.h>
131#endif 131#endif
132#include <errno.h> 132#include <errno.h>
133#include <inttypes.h> 133#include <inttypes.h>
134#include <limits.h> 134#include <limits.h>
135#include <time.h> 135#include <time.h>
136 136
137#include "make.h" 137#include "make.h"
138#include "dir.h" 138#include "dir.h"
139#include "job.h" 139#include "job.h"
140#include "metachar.h" 140#include "metachar.h"
141 141
142/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ 142/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
143MAKE_RCSID("$NetBSD: var.c,v 1.868 2021/03/14 17:34:50 rillig Exp $"); 143MAKE_RCSID("$NetBSD: var.c,v 1.869 2021/03/14 17:38:24 rillig Exp $");
144 144
145typedef enum VarFlags { 145typedef enum VarFlags {
146 VFL_NONE = 0, 146 VFL_NONE = 0,
147 147
148 /* 148 /*
149 * The variable's value is currently being used by Var_Parse or 149 * The variable's value is currently being used by Var_Parse or
150 * Var_Subst. This marker is used to avoid endless recursion. 150 * Var_Subst. This marker is used to avoid endless recursion.
151 */ 151 */
152 VFL_IN_USE = 1 << 0, 152 VFL_IN_USE = 1 << 0,
153 153
154 /* 154 /*
155 * The variable comes from the environment. 155 * The variable comes from the environment.
156 * These variables are not registered in any GNode, therefore they 156 * These variables are not registered in any GNode, therefore they
@@ -3420,29 +3420,30 @@ ApplyModifier_Remember(const char **pp,  @@ -3420,29 +3420,30 @@ ApplyModifier_Remember(const char **pp,
3420 const char *mod = *pp; 3420 const char *mod = *pp;
3421 FStr name; 3421 FStr name;
3422 3422
3423 if (!ModMatchEq(mod, "_", st)) 3423 if (!ModMatchEq(mod, "_", st))
3424 return AMR_UNKNOWN; 3424 return AMR_UNKNOWN;
3425 3425
3426 name = FStr_InitRefer("_"); 3426 name = FStr_InitRefer("_");
3427 if (mod[1] == '=') { 3427 if (mod[1] == '=') {
3428 /* 3428 /*
3429 * XXX: This ad-hoc call to strcspn deviates from the usual 3429 * XXX: This ad-hoc call to strcspn deviates from the usual
3430 * behavior defined in ParseModifierPart. This creates an 3430 * behavior defined in ParseModifierPart. This creates an
3431 * unnecessary, undocumented inconsistency in make. 3431 * unnecessary, undocumented inconsistency in make.
3432 */ 3432 */
3433 size_t n = strcspn(mod + 2, ":)}"); 3433 const char *arg = mod + 2;
3434 *pp = mod + 2 + n; 3434 size_t argLen = strcspn(arg, ":)}");
3435 name = FStr_InitOwn(bmake_strldup(mod + 2, n)); 3435 *pp = arg + argLen;
 3436 name = FStr_InitOwn(bmake_strldup(arg, argLen));
3436 } else 3437 } else
3437 *pp = mod + 1; 3438 *pp = mod + 1;
3438 3439
3439 if (expr->eflags & VARE_WANTRES) 3440 if (expr->eflags & VARE_WANTRES)
3440 Var_Set(expr->scope, name.str, expr->value.str); 3441 Var_Set(expr->scope, name.str, expr->value.str);
3441 FStr_Done(&name); 3442 FStr_Done(&name);
3442 3443
3443 return AMR_OK; 3444 return AMR_OK;
3444} 3445}
3445 3446
3446/* 3447/*
3447 * Apply the given function to each word of the variable value, 3448 * Apply the given function to each word of the variable value,
3448 * for a single-letter modifier such as :H, :T. 3449 * for a single-letter modifier such as :H, :T.