aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-06-06 12:48:11 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-06-06 12:48:11 +0200
commitf4789164e0716a8b1f98cf4149a3eb2dad485b8b (patch)
tree3bf9d3c6df8189d60587f9f0e20013569c85bb09
parent5f84c5633663f6ee8c9cc3a4608b86d4b56b39d6 (diff)
downloadbusybox-w32-f4789164e0716a8b1f98cf4149a3eb2dad485b8b.tar.gz
busybox-w32-f4789164e0716a8b1f98cf4149a3eb2dad485b8b.tar.bz2
busybox-w32-f4789164e0716a8b1f98cf4149a3eb2dad485b8b.zip
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>
-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)
2494 * If src or dst is NULL, use $0. 2494 * If src or dst is NULL, use $0.
2495 * If subexp != 0, enable subexpression matching (\0-\9). 2495 * If subexp != 0, enable subexpression matching (\0-\9).
2496 */ 2496 */
2497static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int subexp) 2497static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest /*,int subexp*/)
2498{ 2498{
2499 char *resbuf; 2499 char *resbuf;
2500 const char *sp; 2500 const char *sp;
@@ -2502,6 +2502,8 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
2502 int regexec_flags; 2502 int regexec_flags;
2503 regmatch_t pmatch[10]; 2503 regmatch_t pmatch[10];
2504 regex_t sreg, *regex; 2504 regex_t sreg, *regex;
2505 /* True only if called to implement gensub(): */
2506 int subexp = (src != dest);
2505 2507
2506 resbuf = NULL; 2508 resbuf = NULL;
2507 residx = 0; 2509 residx = 0;
@@ -2549,7 +2551,6 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
2549 } 2551 }
2550 } 2552 }
2551 2553
2552 regexec_flags = REG_NOTBOL;
2553 sp += eo; 2554 sp += eo;
2554 if (match_no == nm) 2555 if (match_no == nm)
2555 break; 2556 break;
@@ -2570,6 +2571,7 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest, int
2570 sp++; 2571 sp++;
2571 residx++; 2572 residx++;
2572 } 2573 }
2574 regexec_flags = REG_NOTBOL;
2573 } 2575 }
2574 2576
2575 resbuf = qrealloc(resbuf, residx + strlen(sp), &resbufsize); 2577 resbuf = qrealloc(resbuf, residx + strlen(sp), &resbufsize);
@@ -2798,16 +2800,16 @@ static NOINLINE var *exec_builtin(node *op, var *res)
2798 res = do_match(an[1], as[0]); 2800 res = do_match(an[1], as[0]);
2799 break; 2801 break;
2800 2802
2801 case B_ge: 2803 case B_ge: /* gensub(regex, repl, matchnum, string) */
2802 awk_sub(an[0], as[1], getvar_i(av[2]), av[3], res, TRUE); 2804 awk_sub(an[0], as[1], /*matchnum:*/getvar_i(av[2]), /*src:*/av[3], /*dst:*/res/*, TRUE*/);
2803 break; 2805 break;
2804 2806
2805 case B_gs: 2807 case B_gs: /* gsub(regex, repl, string) */
2806 setvar_i(res, awk_sub(an[0], as[1], 0, av[2], av[2], FALSE)); 2808 setvar_i(res, awk_sub(an[0], as[1], /*matchnum:all*/0, /*src:*/av[2], /*dst:*/av[2]/*, FALSE*/));
2807 break; 2809 break;
2808 2810
2809 case B_su: 2811 case B_su: /* sub(regex, repl, string) */
2810 setvar_i(res, awk_sub(an[0], as[1], 1, av[2], av[2], FALSE)); 2812 setvar_i(res, awk_sub(an[0], as[1], /*matchnum:first*/1, /*src:*/av[2], /*dst:*/av[2]/*, FALSE*/));
2811 break; 2813 break;
2812 } 2814 }
2813 2815