memchr() vs. memscan()
Why do we have memchr() and memscan() implementations in lib/string.c? As far as I can see the one may be derived from the other easily.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Why do we have
memchr()andmemscan()implementations inlib/string.c? As far as I can see the one may be derived from the other easily.
Well, memchr() is the C standard thing, and the one arches are more likely to (and do) provide custom implementations of. memscan() seems to be to memchr() as strchrnul() is to strchr(), and judging by the number of callers, I don't think any optimizations or a separate C implementation is really worth it. So yes, by all means we can replace its entire body by
return memchr(addr, c, size) ?: addr + size;
That's possibly even a win for the arches that do provide their own memchr(), but again, performance of this one doesn't matter at all. But the tiny kernel folks might appreciate this.
Rasmus