streq(), wcseq(): New functions to compare strings for equality
Alejandro Colomar
alx@kernel.org
Fri Aug 29 16:58:53 GMT 2025
Hi Wilco,
On Fri, Aug 29, 2025 at 04:50:54PM +0000, Wilco Dijkstra wrote:
> Hi Alejandro,
>
> If it were an inline function or macro it seems fine as syntactic sugar.
> However I think it would be wrong to define this as an exported symbol
> that must be supported by libraries - either you end up with 2 copies of
> strcmp (bad) or you end up calling a small streq function which calls
> strcmp and adjusts the return value (also bad).
It doesn't need to be a symbol. I think it would be fine as an inline
function. (I'd prefer an inline function over a macro.)
>
> Eg. on AArch64 streq looks like:
>
> streq:
> stp x29, x30, [sp, -16]!
> mov x29, sp
> bl strcmp
> cmp w0, 0
> ldp x29, x30, [sp], 16
> cset w0, eq
> ret
Alternatively, you could implement streq without calling strcmp, and
maybe that would be smaller/faster than strcmp(3)?
Have a lovely day!
Alex
> That's a lot of extra overhead, so most people would continue using
>
> #define streq(X,Y) strcmp(X,Y) == 0
>
> as that's simpler and faster.
>
> Inlined it would essentially become a nop - and it would make it possible
> to add a new symbol similar to __memcmpeq to enable implementations
> that only provide eq/ne return value.
--
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250829/f90d0086/attachment.sig>
More information about the Libc-alpha
mailing list