Quoth NRK <n...@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,



Reply via email to