Hi Ian,

On Thu, Feb 19, 2026 at 12:25:24PM +0000, Ian Collier via Mutt-dev wrote:
> On Thu, Feb 19, 2026 at 12:51:57PM +0100, Alejandro Colomar via Mutt-dev 
> wrote:
> > An inline function with that would be an alternative.  A macro is more
> > compact, though, and can be implemented as a one-liner.  When
> > implementing several of these, it can help readability of the entire set
> > of APIs if they fit in a compact space and they are very similar:
> 
> But in your implementation of this you've already pre-defined a macro
> (streq) - why not predefine a macro or inline function called, say,
> is_member, to do the work and then your macros for each indivdual case
> can be trivial as well as more readable.
> 
> > The strchrnul(3) version seems to have significantly less instructions.
>  
> I see.  But the point is moot if strchrnul is not implemented on the
> system.  In addition I think the intent is slightly less clear, but
> maybe that's just me.

The benefit of abstracting strchrnul(3) instead of is_member() is that
strchrnul(3) is quasi-standard, so people know what it does without
having to read its documentation --and even if you have to read the
documentation, it's pretty easy to understand and remember forever--.

Abstracting streq(3) is also trivial for readability.  It has only one
possible meaning.  (And it is implemented in gnulib, and has a manual
page, so people can even consult that.)

is_member(), on the other hand, would be some function of ours that
would have to be checked every now and then to remember exactly what it
does.  So, is_member() would hurt readability more than strchrnul(),
IMO.

I will later compare assembly of the is_member() version with an
strchrnul() provided by us, but I expect it to be quite similar, so
we'd be having more performance on most systems by using strchrnul(3)
and then the performance wouldn't be worse on OpenBSD.

Finally, at least to me, code without branches is more readable, as my
brain doesn't have to branch.  I find the code with strchrnul(3) more
readable, once you get used to streq(3) and strchrnul(3).


Have a lovely day!
Alex

> 
> imc

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).

Attachment: signature.asc
Description: PGP signature

Reply via email to