[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox-cvs
Subject:    [git commit] ash: speed up ${v//pattern/repl}
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2021-07-25 19:54:14
Message-ID: 20210725192945.2BC1388F4E () busybox ! osuosl ! org
[Download RAW message or body]

commit: https://git.busybox.net/busybox/commit/?id=53d45c934f54b7931cc736eba42903cb1f6d4632
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
subevalvar                                          1447    1457     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 shell/ash.c | 17 ++++++++++-------
 1 file 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,
 		while (idx <= end) {
  try_to_match:
 			if (no_meta_len == 0) {
-				/* pattern has meta chars, have to glob; or ENABLE_ASH_OPTIMIZE_FOR_SIZE  */
+				/* pattern has meta chars, have to glob; or ENABLE_ASH_OPTIMIZE_FOR_SIZE */
 				loc = scanright(idx, rmesc, rmescend, str, quotes, /*match_at_start:*/ 1);
 			} else {
 				/* Testcase for very slow replace (performs about 22k replaces):
@@ -7292,16 +7292,19 @@ subevalvar(char *start, char *str, int strloc,
 				 * 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}
 				 * echo "${x//:/|}"
 				 */
-				size_t n;
 				if (strncmp(rmesc, str, no_meta_len) != 0)
 					goto no_match;
-				n = no_meta_len;
 				loc = idx;
-				do {
-					if (quotes && (unsigned char)*loc == CTLESC)
+				if (!quotes) {
+					loc += no_meta_len;
+				} else {
+					size_t n = no_meta_len;
+					do {
+						if ((unsigned char)*loc == CTLESC)
+							loc++;
 						loc++;
-					loc++;
-				} while (--n != 0);
+					} while (--n != 0);
+				}
 			}
 			//bb_error_msg("scanright('%s'):'%s'", str, loc);
 			if (!loc) {
_______________________________________________
busybox-cvs mailing list
busybox-cvs@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic