Re: [PATCH] lib/string.c: Improve strcasecmp speed by not lowering if chars match

From: Nathan Moinvaziri
Date: Tue Oct 25 2022 - 19:28:11 EST


On 10/25/2022 12:32 PM, Christophe JAILLET wrote:
> Hi,
> the algorithm on github is not the same as the one posted here.
>
> IIUC, the one on github is wrong. If you compare 2 strings that are
> the same, they will have the same length, and "if (c1 == c2)
> continue;" will go one past the end of the strings. And the result
> will be <0 or 0 or >0 depending the the char *after* the trailing \0.
>
> On the other side, the results of the benchmark on github are likely
> not accurate with the algorithm posted here, because there is one more
> test in each loop ("while (c1 != 0)") as long as the 2 strings are the
> same.
> On github this test is skipped because you will go through the "continue"
>
> CJ

Hi CJ,

Thanks for catching that, I had changed it at the last second. I have
updated the code and the benchmarks to what I initially proposed in the
patch. Results are about +/-1% from previously.

Nathan