sh: Keep output buffer across builtins.
Allocating and deallocating repeatedly the 1024-byte buffer for stdout from builtins costs CPU time for little or no benefit. A simple loop containing builtins that write to a file descriptor, such as i=0; while [ "$i" -lt 1000000 ]; do printf .; i=$((i+1)); done >/dev/null is over 10% faster in a simple benchmark on an amd64 virtual machine.
This commit is contained in:
parent
de29cd0869
commit
29717eb029
@ -254,14 +254,7 @@ flushout(struct output *dest)
|
||||
void
|
||||
freestdout(void)
|
||||
{
|
||||
INTOFF;
|
||||
if (output.buf) {
|
||||
ckfree(output.buf);
|
||||
output.nextc = NULL;
|
||||
output.buf = NULL;
|
||||
output.bufend = NULL;
|
||||
}
|
||||
INTON;
|
||||
output.nextc = output.buf;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user