https://bugs.kde.org/show_bug.cgi?id=397083

--- Comment #8 from Paul Floyd <pjfl...@wanadoo.fr> ---
It was just a copy and quick adaptation of the memchr representation. There are
other issues - the byte count isn't right either.

There's a lot less benefit to using a loop of UWord steps since UWord is only
2x the size of wchar_t (whilst for memchr it is 8x the size of char).

Looking at a couple of libc implementations, FreeBSD keeps it very simple, no
real effort to optimize.

wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n)
{
        size_t i;

        for (i = 0; i < n; i++) {
                if (*s1 != *s2) {
                        /* wchar might be unsigned */
                        return *s1 > *s2 ? 1 : -1;
                }
                s1++;
                s2++;
        }
        return 0;
}

GNU libc does try harder - though that also has to work on Windows where
wchar_t is 16bits where I expect there will be more benefit.

Code is a bit longer so here's the link. In short, an unrolled loop doing 4
whar_ts at a time followed by 3 ifs to handle the remainder.

https://elixir.bootlin.com/glibc/glibc-2.37/source/wcsmbs/wmemcmp.c#L25

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to