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:
Jilles Tjoelker 2017-05-18 22:10:04 +00:00
parent de29cd0869
commit 29717eb029
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=318502

View File

@ -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;
}