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(1): switch memory handling from MFStr to FStr
details: https://anonhg.NetBSD.org/src/rev/4cba002e35a3
branches: trunk
changeset: 958047:4cba002e35a3
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Dec 21 00:20:58 2020 +0000
description:
make(1): switch memory handling from MFStr to FStr
This makes all intermediate strings constant. For this simple
search-and-replace refactoring, all intermediate locations where the
"current value of the expression" was stored had to be of the type
MFStr.
Using FStr instead of MFStr allows to save a few memory allocations,
which will be done in the follow-up commits.
diffstat:
usr.bin/make/var.c | 131 ++++++++++++++++++++++++++--------------------------
1 files changed, 66 insertions(+), 65 deletions(-)
diffs (truncated from 533 to 300 lines):
diff -r de913b390a70 -r 4cba002e35a3 usr.bin/make/var.c
--- a/usr.bin/make/var.c Mon Dec 21 00:11:29 2020 +0000
+++ b/usr.bin/make/var.c Mon Dec 21 00:20:58 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.757 2020/12/21 00:11:29 rillig Exp $ */
+/* $NetBSD: var.c,v 1.758 2020/12/21 00:20:58 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.757 2020/12/21 00:11:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.758 2020/12/21 00:20:58 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@@ -1930,7 +1930,7 @@
* The new value of the expression, after applying the modifier,
* never NULL.
*/
- MFStr newVal;
+ FStr newVal;
/* Word separator in expansions (see the :ts modifier). */
char sep;
/*
@@ -2225,7 +2225,7 @@
args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
prev_sep = st->sep;
st->sep = ' '; /* XXX: should be st->sep for consistency */
- st->newVal = MFStr_InitOwn(
+ st->newVal = FStr_InitOwn(
ModifyWords(val, ModifyWord_Loop, &args, st->oneBigWord, st->sep));
st->sep = prev_sep;
/* XXX: Consider restoring the previous variable instead of deleting. */
@@ -2237,7 +2237,7 @@
/* :Ddefined or :Uundefined */
static ApplyModifierResult
-ApplyModifier_Defined(const char **pp, char *val, ApplyModifiersState *st)
+ApplyModifier_Defined(const char **pp, const char *val, ApplyModifiersState *st)
{
Buffer buf;
const char *p;
@@ -2286,9 +2286,9 @@
ApplyModifiersState_Define(st);
if (eflags & VARE_WANTRES) {
- st->newVal = MFStr_InitOwn(Buf_Destroy(&buf, FALSE));
+ st->newVal = FStr_InitOwn(Buf_Destroy(&buf, FALSE));
} else {
- st->newVal = MFStr_InitRefer(val);
+ st->newVal = FStr_InitRefer(val);
Buf_Destroy(&buf, TRUE);
}
return AMR_OK;
@@ -2299,7 +2299,7 @@
ApplyModifier_Literal(const char **pp, ApplyModifiersState *st)
{
ApplyModifiersState_Define(st);
- st->newVal = MFStr_InitOwn(bmake_strdup(st->var->name.str));
+ st->newVal = FStr_InitOwn(bmake_strdup(st->var->name.str));
(*pp)++;
return AMR_OK;
}
@@ -2345,7 +2345,7 @@
utc = 0;
*pp = mod + 6;
}
- st->newVal = MFStr_InitOwn(VarStrftime(val, TRUE, utc));
+ st->newVal = FStr_InitOwn(VarStrftime(val, TRUE, utc));
return AMR_OK;
}
@@ -2372,7 +2372,7 @@
utc = 0;
*pp = mod + 9;
}
- st->newVal = MFStr_InitOwn(VarStrftime(val, FALSE, utc));
+ st->newVal = FStr_InitOwn(VarStrftime(val, FALSE, utc));
return AMR_OK;
}
@@ -2383,7 +2383,7 @@
if (!ModMatch(*pp, "hash", st->endc))
return AMR_UNKNOWN;
- st->newVal = MFStr_InitOwn(VarHash(val));
+ st->newVal = FStr_InitOwn(VarHash(val));
*pp += 4;
return AMR_OK;
}
@@ -2408,7 +2408,7 @@
}
if (path == NULL)
path = bmake_strdup(st->var->name.str);
- st->newVal = MFStr_InitOwn(path);
+ st->newVal = FStr_InitOwn(path);
(*pp)++;
return AMR_OK;
@@ -2430,9 +2430,9 @@
errfmt = NULL;
if (st->eflags & VARE_WANTRES)
- st->newVal = MFStr_InitOwn(Cmd_Exec(cmd, &errfmt));
+ st->newVal = FStr_InitOwn(Cmd_Exec(cmd, &errfmt));
else
- st->newVal = MFStr_InitOwn(bmake_strdup(""));
+ st->newVal = FStr_InitOwn(bmake_strdup(""));
if (errfmt != NULL)
Error(errfmt, cmd); /* XXX: why still return AMR_OK? */
free(cmd);
@@ -2483,7 +2483,7 @@
Buf_AddInt(&buf, 1 + (int)i);
}
- st->newVal = MFStr_InitOwn(Buf_Destroy(&buf, FALSE));
+ st->newVal = FStr_InitOwn(Buf_Destroy(&buf, FALSE));
return AMR_OK;
}
@@ -2560,7 +2560,7 @@
st->var->name.str, val, pattern);
callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
- st->newVal = MFStr_InitOwn(ModifyWords(val, callback, pattern,
+ st->newVal = FStr_InitOwn(ModifyWords(val, callback, pattern,
st->oneBigWord, st->sep));
free(pattern);
return AMR_OK;
@@ -2624,7 +2624,7 @@
break;
}
- st->newVal = MFStr_InitOwn(ModifyWords(val, ModifyWord_Subst, &args,
+ st->newVal = FStr_InitOwn(ModifyWords(val, ModifyWord_Subst, &args,
oneBigWord, st->sep));
free(lhs);
@@ -2694,7 +2694,7 @@
args.nsub = args.re.re_nsub + 1;
if (args.nsub > 10)
args.nsub = 10;
- st->newVal = MFStr_InitOwn(
+ st->newVal = FStr_InitOwn(
ModifyWords(val, ModifyWord_SubstRegex, &args,
oneBigWord, st->sep));
regfree(&args.re);
@@ -2709,7 +2709,7 @@
ApplyModifier_Quote(const char **pp, const char *val, ApplyModifiersState *st)
{
if ((*pp)[1] == st->endc || (*pp)[1] == ':') {
- st->newVal = MFStr_InitOwn(VarQuote(val, **pp == 'q'));
+ st->newVal = FStr_InitOwn(VarQuote(val, **pp == 'q'));
(*pp)++;
return AMR_OK;
} else
@@ -2789,7 +2789,7 @@
}
ok:
- st->newVal = MFStr_InitOwn(
+ st->newVal = FStr_InitOwn(
ModifyWords(val, ModifyWord_Copy, NULL, st->oneBigWord, st->sep));
return AMR_OK;
}
@@ -2824,7 +2824,7 @@
/* :tA, :tu, :tl, :ts<separator>, etc. */
static ApplyModifierResult
-ApplyModifier_To(const char **pp, char *val, ApplyModifiersState *st)
+ApplyModifier_To(const char **pp, const char *val, ApplyModifiersState *st)
{
const char *mod = *pp;
assert(mod[0] == 't');
@@ -2844,7 +2844,7 @@
/* Check for two-character options: ":tu", ":tl" */
if (mod[1] == 'A') { /* absolute path */
- st->newVal = MFStr_InitOwn(
+ st->newVal = FStr_InitOwn(
ModifyWords(val, ModifyWord_Realpath, NULL,
st->oneBigWord, st->sep));
*pp = mod + 2;
@@ -2852,20 +2852,20 @@
}
if (mod[1] == 'u') { /* :tu */
- st->newVal = MFStr_InitOwn(str_toupper(val));
+ st->newVal = FStr_InitOwn(str_toupper(val));
*pp = mod + 2;
return AMR_OK;
}
if (mod[1] == 'l') { /* :tl */
- st->newVal = MFStr_InitOwn(str_tolower(val));
+ st->newVal = FStr_InitOwn(str_tolower(val));
*pp = mod + 2;
return AMR_OK;
}
if (mod[1] == 'W' || mod[1] == 'w') { /* :tW, :tw */
st->oneBigWord = mod[1] == 'W';
- st->newVal = MFStr_InitRefer(val);
+ st->newVal = FStr_InitRefer(val);
*pp = mod + 2;
return AMR_OK;
}
@@ -2877,7 +2877,7 @@
/* :[#], :[1], :[-1..1], etc. */
static ApplyModifierResult
-ApplyModifier_Words(const char **pp, char *val, ApplyModifiersState *st)
+ApplyModifier_Words(const char **pp, const char *val, ApplyModifiersState *st)
{
char *estr;
int first, last;
@@ -2899,7 +2899,7 @@
if (estr[0] == '#' && estr[1] == '\0') { /* Found ":[#]" */
if (st->oneBigWord) {
- st->newVal = MFStr_InitOwn(bmake_strdup("1"));
+ st->newVal = FStr_InitOwn(bmake_strdup("1"));
} else {
Buffer buf;
@@ -2910,7 +2910,7 @@
/* 3 digits + '\0' is usually enough */
Buf_InitSize(&buf, 4);
Buf_AddInt(&buf, (int)ac);
- st->newVal = MFStr_InitOwn(Buf_Destroy(&buf, FALSE));
+ st->newVal = FStr_InitOwn(Buf_Destroy(&buf, FALSE));
}
goto ok;
}
@@ -2918,14 +2918,14 @@
if (estr[0] == '*' && estr[1] == '\0') {
/* Found ":[*]" */
st->oneBigWord = TRUE;
- st->newVal = MFStr_InitRefer(val);
+ st->newVal = FStr_InitRefer(val);
goto ok;
}
if (estr[0] == '@' && estr[1] == '\0') {
/* Found ":[@]" */
st->oneBigWord = FALSE;
- st->newVal = MFStr_InitRefer(val);
+ st->newVal = FStr_InitRefer(val);
goto ok;
}
@@ -2954,7 +2954,7 @@
if (first == 0 && last == 0) {
/* ":[0]" or perhaps ":[0..0]" */
st->oneBigWord = TRUE;
- st->newVal = MFStr_InitRefer(val);
+ st->newVal = FStr_InitRefer(val);
goto ok;
}
@@ -2963,7 +2963,7 @@
goto bad_modifier;
/* Normal case: select the words described by first and last. */
- st->newVal = MFStr_InitOwn(
+ st->newVal = FStr_InitOwn(
VarSelectWords(st->sep, st->oneBigWord, val, first, last));
ok:
@@ -3027,7 +3027,7 @@
return AMR_BAD;
}
- st->newVal = MFStr_InitOwn(Words_JoinFree(words));
+ st->newVal = FStr_InitOwn(Words_JoinFree(words));
return AMR_OK;
}
@@ -3070,10 +3070,10 @@
}
if (value) {
- st->newVal = MFStr_InitOwn(then_expr);
+ st->newVal = FStr_InitOwn(then_expr);
free(else_expr);
} else {
- st->newVal = MFStr_InitOwn(else_expr);
+ st->newVal = FStr_InitOwn(else_expr);
free(then_expr);
}
ApplyModifiersState_Define(st);
@@ -3177,14 +3177,15 @@
}
}
free(val);
- st->newVal = MFStr_InitOwn(bmake_strdup(""));
+ st->newVal = FStr_InitOwn(bmake_strdup(""));
Home |
Main Index |
Thread Index |
Old Index