Skip to content
Snippets Groups Projects
Commit 42b730b0 authored by Herbert Xu's avatar Herbert Xu
Browse files

builtin: Fix echo performance regression


The commit d6c0e1e2 ("[BUILTIN]
Handle embedded NULs correctly in printf") caused a performance
regression in the echo built-in because every echo call now goes
through the printf %b slow path where the string is always printed
twice to ensure the space padding is correct in the presence of
NUL characters.  In fact this regression applies to printf %b as
well.

This is easily fixed by making printf %b take the fast path when
no precision/field width modifiers are present.

This patch also changes the second strchurnul call to strspn which
generates slightly better code.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 36128c90
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -98,20 +98,25 @@ static int print_escape_str(const char *f, int *param, int *array, char *s)
int total;
 
setstackmark(&smark);
done = conv_escape_str(s, &p);
q = stackblock();
len = p - q;
done = conv_escape_str(s, &q);
p = stackblock();
len = q - p;
total = len - 1;
if (f[1] == 's')
goto easy;
 
p = makestrspace(len, p);
memset(p, 'X', len - 1);
p[len - 1] = 0;
p = makestrspace(len, q);
memset(p, 'X', total);
p[total] = 0;
 
q = stackblock();
total = ASPF(&p, f, p);
 
len = strchrnul(p, 'X') - p;
memcpy(p + len, q, strchrnul(p + len, ' ') - (p + len));
memcpy(p + len, q, strspn(p + len, "X"));
 
easy:
out1mem(p, total);
 
popstackmark(&smark);
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment