提交 37460f5d 编写于 作者: D Denys Vlasenko

hush: tweak ${var/pattern/repl} optimization

function                                             old     new   delta
expand_one_var                                      2507    2502      -5
Signed-off-by: NDenys Vlasenko <vda.linux@googlemail.com>
上级 49cc3cac
......@@ -6466,17 +6466,16 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
/* ${var/[/]pattern[/repl]} helpers */
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.
* 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;echo ${#x}
* echo "${x//:/|}"
*/
char *found = strstr(val, pattern);
if (found)
*size = strlen(pattern);
return found;
*size = sz;
return strstr(val, pattern);
}
while (1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册