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>
This commit is contained in:
parent
49cc3cac30
commit
37460f5daf
@ -6466,17 +6466,16 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
|
|||||||
/* ${var/[/]pattern[/repl]} helpers */
|
/* ${var/[/]pattern[/repl]} helpers */
|
||||||
static char *strstr_pattern(char *val, const char *pattern, int *size)
|
static char *strstr_pattern(char *val, const char *pattern, int *size)
|
||||||
{
|
{
|
||||||
if (!strpbrk(pattern, "*?[\\")) {
|
int sz = strcspn(pattern, "*?[\\");
|
||||||
|
if (pattern[sz] == '\0') {
|
||||||
/* Optimization for trivial patterns.
|
/* Optimization for trivial patterns.
|
||||||
* Testcase for very slow replace (performs about 22k replaces):
|
* Testcase for very slow replace (performs about 22k replaces):
|
||||||
* 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=$x$x;echo ${#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$x;echo ${#x}
|
||||||
* echo "${x//:/|}"
|
* echo "${x//:/|}"
|
||||||
*/
|
*/
|
||||||
char *found = strstr(val, pattern);
|
*size = sz;
|
||||||
if (found)
|
return strstr(val, pattern);
|
||||||
*size = strlen(pattern);
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user