mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
cut: avoid fwrite calls for smaller amounts of data
This is quite significant: yes abcdfeg | head -n1MB > big-file $ time src/cut-before -b1,3 big-file >/dev/null real 0m0.050s $ time src/cut-after -b1,3 big-file >/dev/null real 0m0.029s
This commit is contained in:
1 parent
a16d56d60c
commit
9817599526
1 file changed
+10
@@ -405,6 +405,16 @@ skip_whitespace_run (mbbuf_t *mbuf, struct mbfield_parser *parser,
|
||||
static void
|
||||
write_bytes (char const *buf, size_t n_bytes)
|
||||
{
|
||||
/* Avoid a function call for smaller amounts,
|
||||
using instead the macro to directly interact with the stdio buffer. */
|
||||
if (n_bytes <= 4)
|
||||
{
|
||||
for (size_t i = 0; i < n_bytes; i++)
|
||||
if (putchar (buf[i]) < 0)
|
||||
write_error ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fwrite (buf, sizeof (char), n_bytes, stdout) != n_bytes)
|
||||
write_error ();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user