Re: mutt_buffer_concat_path is broken [PATCH: 1/1] Version 2

Alejandro Colomar via Mutt-dev <[email protected]> Fri, 8 May 2026 15:20:00 +0200
Newsgroups gmane.mail.mutt.devel
Message-ID <af3iSKUNg12ZOG-6@devuan>
Hi Derek,

On 2026-05-08T07:52:39-0400, Derek Martin wrote:
> On Fri, May 08, 2026 at 07:47:15AM -0400, Derek Martin wrote:
> > On Fri, May 08, 2026 at 08:08:13AM +0200, Rene Kita wrote:
> > > strspn is one of those function I can't get into my head, that's why I
> > > always end with a loop. :-) I should really try to remember it.
> > 
> > I prefer the loop:  They're functionally equivalent, nearly as
> > succinct, and far more explicit.  you're not the only one who has
> > trouble remembering it.  In professional production code I've seen
> > loops far more often than strspn.  Its name doesn't really lend to one
> > remembering what it does, like a lot of the less-commonly-used C
> > library functions.  =8^)
> 
> FWIW, it's also very slightly more efficient.  strspn will loop over
> the string, exactly as the while loop does, but a) it adds the
> overhead of the function call, and b) then after the call returns you
> have to do the pointer math to get where you want to go.  The while
> loop solution has neither cost.

I'd like to see evidence that compilers are unable to perform this
optimization these days.  Most likely, they know about strspn(3) and
optimize it as much as you could with a manual loop.

But even if I saw evidence (which I doubt), I think the fact that it
doesn't allow silly mistakes when writing the loop already counters the
small efficiency theoretical gains.


Cheers,
Alex

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmn94wAACgkQ64mZXMKQ
wqmISQ/+PiXHNEEKUJYbMElcSvlcQFGNBDcGIatOZLI77f597xUfk9TGQJxbOUoB
WcVg32uwszE3yNT4oTvpjOz/vgsHXYMUW0EPGIoYJgdjZZ32E3jcGkJR8OO2NSnI
1IneSKAsl7NZs1U42dMzW4ySPuH1cYitpEiij+dy4vCiyBz56AV4gGP2oOmHVRey
LGHh1HoPioDKgntCrUZC3gRExiA8l0SbyH3thChe82KT8z8mB1Z3hAHyzcCWd06l
RbsAL8/40mcWH6me4oEWGdW8cMb97+VDCUD0w6Lt+hvZdA9R3oElBqmKc8oxYodp
pt3JgD+yaQY7widAuvg+KoVS5GKUhPYYubm3gFve1wdYbftgYGDqpbgAdOozqp/y
b0pucdwAM0P9twb9r//5OaDMbbm0xKHgwbIkrZeEeURwVMrg9/OF9k36Z2rgdWXW
idxovr5ESjQWOCg1DWnjCisbDpfjkEY7a1R83dY7/VvJ2vTybcBatS6T6gdXYRQW
bbmeEqBrBQu5pdGaHJgxlOA/nVV2YTUxjwjBose4q76x/IH78SWfTK0di4lUYqwZ
jFcSoN5mLcuw+0Jw/JqGaCQiZfobI/ls7RMmAksvUFJPomvhXX/oQGss8WCGxnyK
tphV9n1bT0Tunu21t0Logpcmj7BeJbBArg+r7CBDscTlckuC4RA=
=e9Sk
-----END PGP SIGNATURE-----