streq(), wcseq(): New functions to compare strings for equality
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Fri Aug 29 16:50:54 GMT 2025
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).
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
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.
Cheers,
Wilco
More information about the Libc-alpha
mailing list