diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-27 18:13:11 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-27 18:13:39 +0200 |
commit | 37460f5daff9b9ed751ce37b912cc61de94adf09 (patch) | |
tree | 6dc76a5d514ab71a2b92c8b4a386c45de46ecc9a | |
parent | 49cc3cac30c504abdbd2c075928f5711da4066e8 (diff) | |
download | busybox-w32-37460f5daff9b9ed751ce37b912cc61de94adf09.tar.gz busybox-w32-37460f5daff9b9ed751ce37b912cc61de94adf09.tar.bz2 busybox-w32-37460f5daff9b9ed751ce37b912cc61de94adf09.zip |
hush: tweak ${var/pattern/repl} optimization
function old new delta
expand_one_var 2507 2502 -5
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index 179155f66..c970d9097 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -6466,17 +6466,16 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p) | |||
6466 | /* ${var/[/]pattern[/repl]} helpers */ | 6466 | /* ${var/[/]pattern[/repl]} helpers */ |
6467 | static char *strstr_pattern(char *val, const char *pattern, int *size) | 6467 | static char *strstr_pattern(char *val, const char *pattern, int *size) |
6468 | { | 6468 | { |
6469 | if (!strpbrk(pattern, "*?[\\")) { | 6469 | int sz = strcspn(pattern, "*?[\\"); |
6470 | if (pattern[sz] == '\0') { | ||
6470 | /* Optimization for trivial patterns. | 6471 | /* Optimization for trivial patterns. |
6471 | * Testcase for very slow replace (performs about 22k replaces): | 6472 | * Testcase for very slow replace (performs about 22k replaces): |
6472 | * x=:::::::::::::::::::::: | 6473 | * x=:::::::::::::::::::::: |
6473 | * x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;echo ${#x} | 6474 | * x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;echo ${#x} |
6474 | * echo "${x//:/|}" | 6475 | * echo "${x//:/|}" |
6475 | */ | 6476 | */ |
6476 | char *found = strstr(val, pattern); | 6477 | *size = sz; |
6477 | if (found) | 6478 | return strstr(val, pattern); |
6478 | *size = strlen(pattern); | ||
6479 | return found; | ||
6480 | } | 6479 | } |
6481 | 6480 | ||
6482 | while (1) { | 6481 | while (1) { |