Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-06-06 13:48:11 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2023-06-06 13:48:11 +0300
commitf4789164e0716a8b1f98cf4149a3eb2dad485b8b (patch)
tree3bf9d3c6df8189d60587f9f0e20013569c85bb09 /editors
parent5f84c5633663f6ee8c9cc3a4608b86d4b56b39d6 (diff)
awk: code shrink
function old new delta awk_sub 544 548 +4 exec_builtin 1136 1130 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-6) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/editors/awk.c b/editors/awk.c
index f77573806..b3871ffc5 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2494,7 +2494,7 @@ static char *awk_printf(node *n, size_t *len)
* If src or dst is NULL, use $0.
* If subexp != 0, enable subexpression matching (\0-\9).
*/
-static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int subexp)
+static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest /*,int subexp*/)
{
char *resbuf;
const char *sp;
@@ -2502,6 +2502,8 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
int regexec_flags;
regmatch_t pmatch[10];
regex_t sreg, *regex;
+ /* True only if called to implement gensub(): */
+ int subexp = (src != dest);
resbuf = NULL;
residx = 0;
@@ -2549,7 +2551,6 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
}
}
- regexec_flags = REG_NOTBOL;
sp += eo;
if (match_no == nm)
break;
@@ -2570,6 +2571,7 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
sp++;
residx++;
}
+ regexec_flags = REG_NOTBOL;
}
resbuf = qrealloc(resbuf, residx + strlen(sp), &resbufsize);
@@ -2798,16 +2800,16 @@ static NOINLINE var *exec_builtin(node *op, var *res)
res = do_match(an[1], as[0]);
break;
- case B_ge:
- awk_sub(an[0], as[1], getvar_i(av[2]), av[3], res, TRUE);
+ case B_ge: /* gensub(regex, repl, matchnum, string) */
+ awk_sub(an[0], as[1], /*matchnum:*/getvar_i(av[2]), /*src:*/av[3], /*dst:*/res/*, TRUE*/);
break;
- case B_gs:
- setvar_i(res, awk_sub(an[0], as[1], 0, av[2], av[2], FALSE));
+ case B_gs: /* gsub(regex, repl, string) */
+ setvar_i(res, awk_sub(an[0], as[1], /*matchnum:all*/0, /*src:*/av[2], /*dst:*/av[2]/*, FALSE*/));
break;
- case B_su:
- setvar_i(res, awk_sub(an[0], as[1], 1, av[2], av[2], FALSE));
+ case B_su: /* sub(regex, repl, string) */
+ setvar_i(res, awk_sub(an[0], as[1], /*matchnum:first*/1, /*src:*/av[2], /*dst:*/av[2]/*, FALSE*/));
break;
}