Alejandro Colomar <[email protected]> writes:

> Hi Ben,
>
> On 2026-02-21T09:47:12-0800, Ben Pfaff wrote:
>> On Sat, Feb 21, 2026 at 1:38 AM Bruno Haible via Gnulib discussion
>> list <[email protected]> wrote:
>> > strchr is a red herring, because this way to define strnul is compiled
>> > less efficiently than (s + strlen (s)). See attached example code.
>> >
>> > The better way is thus (s + strlen (s)), and since it evaluates s twice,
>> > it means we need an inline function, not a macro. But we have the machinery
>> > for inline functions in Gnulib.
>> 
>> Maybe it would be a good idea to suggest an update to the glibc manual,
>
> Agree.
>
>> because it says that strchr(s, '\0') is faster than s + strlen(s):
>
> Huh; I'm curious about why that's said in the glibc manual.
> I would be surprised if that were true, given strchr() must perform two
> comparisons per iteration.  And indeed, some experiment shows that
> s+strlen(s) is faster:

Like much of the glibc manual, those lines were written 25 years ago. :)

Collin

Reply via email to