diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-03 12:20:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-03 12:20:36 +0200 |
commit | 90404ed2f62a872ffd9a555660b7ce17fae372d8 (patch) | |
tree | 821fc971510b0a85a9501f6054a81e8553532289 | |
parent | 0e3ef4efb061366bfa4b9609fe3a03f3a1e40f0e (diff) | |
download | busybox-w32-90404ed2f62a872ffd9a555660b7ce17fae372d8.tar.gz busybox-w32-90404ed2f62a872ffd9a555660b7ce17fae372d8.tar.bz2 busybox-w32-90404ed2f62a872ffd9a555660b7ce17fae372d8.zip |
awk: match(): code shrink
function old new delta
do_match - 165 +165
exec_builtin_match 202 - -202
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/0 up/down: 165/-202) Total: -37 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/editors/awk.c b/editors/awk.c index e4dd6684c..649198d15 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2497,26 +2497,24 @@ static NOINLINE int do_mktime(const char *ds) | |||
2497 | } | 2497 | } |
2498 | 2498 | ||
2499 | /* Reduce stack usage in exec_builtin() by keeping match() code separate */ | 2499 | /* Reduce stack usage in exec_builtin() by keeping match() code separate */ |
2500 | static NOINLINE void exec_builtin_match(node *an1, const char *as0, var *res) | 2500 | static NOINLINE var *do_match(node *an1, const char *as0) |
2501 | { | 2501 | { |
2502 | regmatch_t pmatch[1]; | 2502 | regmatch_t pmatch[1]; |
2503 | regex_t sreg, *re; | 2503 | regex_t sreg, *re; |
2504 | int n; | 2504 | int n, start, len; |
2505 | 2505 | ||
2506 | re = as_regex(an1, &sreg); | 2506 | re = as_regex(an1, &sreg); |
2507 | n = regexec(re, as0, 1, pmatch, 0); | 2507 | n = regexec(re, as0, 1, pmatch, 0); |
2508 | if (n == 0) { | ||
2509 | pmatch[0].rm_so++; | ||
2510 | pmatch[0].rm_eo++; | ||
2511 | } else { | ||
2512 | pmatch[0].rm_so = 0; | ||
2513 | pmatch[0].rm_eo = -1; | ||
2514 | } | ||
2515 | if (re == &sreg) | 2508 | if (re == &sreg) |
2516 | regfree(re); | 2509 | regfree(re); |
2517 | setvar_i(newvar("RSTART"), pmatch[0].rm_so); | 2510 | start = 0; |
2518 | setvar_i(newvar("RLENGTH"), pmatch[0].rm_eo - pmatch[0].rm_so); | 2511 | len = -1; |
2519 | setvar_i(res, pmatch[0].rm_so); | 2512 | if (n == 0) { |
2513 | start = pmatch[0].rm_so + 1; | ||
2514 | len = pmatch[0].rm_eo - pmatch[0].rm_so; | ||
2515 | } | ||
2516 | setvar_i(newvar("RLENGTH"), len); | ||
2517 | return setvar_i(newvar("RSTART"), start); | ||
2520 | } | 2518 | } |
2521 | 2519 | ||
2522 | /* Reduce stack usage in evaluate() by keeping builtins' code separate */ | 2520 | /* Reduce stack usage in evaluate() by keeping builtins' code separate */ |
@@ -2686,7 +2684,7 @@ static NOINLINE var *exec_builtin(node *op, var *res) | |||
2686 | break; | 2684 | break; |
2687 | 2685 | ||
2688 | case B_ma: | 2686 | case B_ma: |
2689 | exec_builtin_match(an[1], as[0], res); | 2687 | res = do_match(an[1], as[0]); |
2690 | break; | 2688 | break; |
2691 | 2689 | ||
2692 | case B_ge: | 2690 | case B_ge: |