aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-07-25 21:54:14 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-07-25 21:54:14 +0200
commit53d45c934f54b7931cc736eba42903cb1f6d4632 (patch)
tree3d8a0ace7cb92842a91763506ba558d2082337f7
parent1310d7b1d106d7ab0ec84ce88c12302cca934230 (diff)
downloadbusybox-w32-53d45c934f54b7931cc736eba42903cb1f6d4632.tar.gz
busybox-w32-53d45c934f54b7931cc736eba42903cb1f6d4632.tar.bz2
busybox-w32-53d45c934f54b7931cc736eba42903cb1f6d4632.zip
ash: speed up ${v//pattern/repl}
function old new delta subevalvar 1447 1457 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 092f3bcc7..b5947147a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7284,7 +7284,7 @@ subevalvar(char *start, char *str, int strloc,
7284 while (idx <= end) { 7284 while (idx <= end) {
7285 try_to_match: 7285 try_to_match:
7286 if (no_meta_len == 0) { 7286 if (no_meta_len == 0) {
7287 /* pattern has meta chars, have to glob; or ENABLE_ASH_OPTIMIZE_FOR_SIZE */ 7287 /* pattern has meta chars, have to glob; or ENABLE_ASH_OPTIMIZE_FOR_SIZE */
7288 loc = scanright(idx, rmesc, rmescend, str, quotes, /*match_at_start:*/ 1); 7288 loc = scanright(idx, rmesc, rmescend, str, quotes, /*match_at_start:*/ 1);
7289 } else { 7289 } else {
7290 /* Testcase for very slow replace (performs about 22k replaces): 7290 /* Testcase for very slow replace (performs about 22k replaces):
@@ -7292,16 +7292,19 @@ subevalvar(char *start, char *str, int strloc,
7292 * 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} 7292 * 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}
7293 * echo "${x//:/|}" 7293 * echo "${x//:/|}"
7294 */ 7294 */
7295 size_t n;
7296 if (strncmp(rmesc, str, no_meta_len) != 0) 7295 if (strncmp(rmesc, str, no_meta_len) != 0)
7297 goto no_match; 7296 goto no_match;
7298 n = no_meta_len;
7299 loc = idx; 7297 loc = idx;
7300 do { 7298 if (!quotes) {
7301 if (quotes && (unsigned char)*loc == CTLESC) 7299 loc += no_meta_len;
7300 } else {
7301 size_t n = no_meta_len;
7302 do {
7303 if ((unsigned char)*loc == CTLESC)
7304 loc++;
7302 loc++; 7305 loc++;
7303 loc++; 7306 } while (--n != 0);
7304 } while (--n != 0); 7307 }
7305 } 7308 }
7306 //bb_error_msg("scanright('%s'):'%s'", str, loc); 7309 //bb_error_msg("scanright('%s'):'%s'", str, loc);
7307 if (!loc) { 7310 if (!loc) {