diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-02 23:38:50 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-02 23:48:48 +0200 |
commit | b705bf55395bf338f9b9888d87e418f67d4f1a29 (patch) | |
tree | 9f496c19d55c9dc221abd4c895c7280d3a3e5095 | |
parent | 646429e05e2f62250da80aa8d98111f3a9818e9a (diff) | |
download | busybox-w32-b705bf55395bf338f9b9888d87e418f67d4f1a29.tar.gz busybox-w32-b705bf55395bf338f9b9888d87e418f67d4f1a29.tar.bz2 busybox-w32-b705bf55395bf338f9b9888d87e418f67d4f1a29.zip |
awk: move match() code out-of-line
function old new delta
exec_builtin_match - 202 +202
exec_builtin 1434 1157 -277
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 202/-277) Total: -75 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/editors/awk.c b/editors/awk.c index c06dd2304..96e06db25 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2465,6 +2465,30 @@ static NOINLINE int do_mktime(const char *ds) | |||
2465 | return mktime(&then); | 2465 | return mktime(&then); |
2466 | } | 2466 | } |
2467 | 2467 | ||
2468 | /* Reduce stack usage in exec_builtin() by keeping match() code separate */ | ||
2469 | static NOINLINE void exec_builtin_match(node *an1, const char *as0, var *res) | ||
2470 | { | ||
2471 | regmatch_t pmatch[1]; | ||
2472 | regex_t sreg, *re; | ||
2473 | int n; | ||
2474 | |||
2475 | re = as_regex(an1, &sreg); | ||
2476 | n = regexec(re, as0, 1, pmatch, 0); | ||
2477 | if (n == 0) { | ||
2478 | pmatch[0].rm_so++; | ||
2479 | pmatch[0].rm_eo++; | ||
2480 | } else { | ||
2481 | pmatch[0].rm_so = 0; | ||
2482 | pmatch[0].rm_eo = -1; | ||
2483 | } | ||
2484 | if (re == &sreg) | ||
2485 | regfree(re); | ||
2486 | setvar_i(newvar("RSTART"), pmatch[0].rm_so); | ||
2487 | setvar_i(newvar("RLENGTH"), pmatch[0].rm_eo - pmatch[0].rm_so); | ||
2488 | setvar_i(res, pmatch[0].rm_so); | ||
2489 | } | ||
2490 | |||
2491 | /* Reduce stack usage in evaluate() by keeping builtins' code separate */ | ||
2468 | static NOINLINE var *exec_builtin(node *op, var *res) | 2492 | static NOINLINE var *exec_builtin(node *op, var *res) |
2469 | { | 2493 | { |
2470 | #define tspl (G.exec_builtin__tspl) | 2494 | #define tspl (G.exec_builtin__tspl) |
@@ -2473,8 +2497,6 @@ static NOINLINE var *exec_builtin(node *op, var *res) | |||
2473 | node *an[4]; | 2497 | node *an[4]; |
2474 | var *av[4]; | 2498 | var *av[4]; |
2475 | const char *as[4]; | 2499 | const char *as[4]; |
2476 | regmatch_t pmatch[1]; | ||
2477 | regex_t sreg, *re; | ||
2478 | node *spl; | 2500 | node *spl; |
2479 | uint32_t isr, info; | 2501 | uint32_t isr, info; |
2480 | int nargs; | 2502 | int nargs; |
@@ -2633,20 +2655,7 @@ static NOINLINE var *exec_builtin(node *op, var *res) | |||
2633 | break; | 2655 | break; |
2634 | 2656 | ||
2635 | case B_ma: | 2657 | case B_ma: |
2636 | re = as_regex(an[1], &sreg); | 2658 | exec_builtin_match(an[1], as[0], res); |
2637 | n = regexec(re, as[0], 1, pmatch, 0); | ||
2638 | if (n == 0) { | ||
2639 | pmatch[0].rm_so++; | ||
2640 | pmatch[0].rm_eo++; | ||
2641 | } else { | ||
2642 | pmatch[0].rm_so = 0; | ||
2643 | pmatch[0].rm_eo = -1; | ||
2644 | } | ||
2645 | setvar_i(newvar("RSTART"), pmatch[0].rm_so); | ||
2646 | setvar_i(newvar("RLENGTH"), pmatch[0].rm_eo - pmatch[0].rm_so); | ||
2647 | setvar_i(res, pmatch[0].rm_so); | ||
2648 | if (re == &sreg) | ||
2649 | regfree(re); | ||
2650 | break; | 2659 | break; |
2651 | 2660 | ||
2652 | case B_ge: | 2661 | case B_ge: |
@@ -2732,7 +2741,9 @@ static rstream *next_input_file(void) | |||
2732 | 2741 | ||
2733 | /* | 2742 | /* |
2734 | * Evaluate node - the heart of the program. Supplied with subtree | 2743 | * Evaluate node - the heart of the program. Supplied with subtree |
2735 | * and place where to store result. Returns ptr to result. | 2744 | * and "res" variable to assign the result to if we evaluate an expression. |
2745 | * If node refers to e.g. a variable or a field, no assignment happens. | ||
2746 | * Return ptr to the result (which may or may not be the "res" variable!) | ||
2736 | */ | 2747 | */ |
2737 | #define XC(n) ((n) >> 8) | 2748 | #define XC(n) ((n) >> 8) |
2738 | 2749 | ||