Re: [hackers] [sbase][PATCH] head: remove useless buffering

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Thu, 19 Dec 2024 12:01:58 +0100

Quoth NRK <nrk_AT_disroot.org>:
> > + while (i < n && (c = fgetc(fp)) != EOF) {
> > + if (fputc(c, stdout) == EOF)
>
> I don't see this as an improvement. Each one of the fgetc and fputc are
> going to go through a mutex lock (along with possibly going through a
> call into a dynamic function).

These kind of things depend so much of the libc implementation that
we should not care about them. The code compiled without -pthread
can link with versions of the library without locks (making getc
equal to getc_unlocked) and in that scenario fputc can be inlined
(in fact, putc that can be used in this case, used to be a macro,
and it is still in some libcs).

This new version seems more idiomatic to me, and it is the usual
way of doing this kind of things. For this reason, I am going to
apply the patch just changing fputc to putc.

Regards,
Received on Thu Dec 19 2024 - 12:01:58 CET

This archive was generated by hypermail 2.3.0 : Thu Dec 19 2024 - 12:12:42 CET