tst: memfs: MemfsFileNameCompare

Use fast loop for ASCII and fall back to
CompareStringW for general case.
This commit is contained in:
Bill Zissimopoulos 2022-05-30 14:13:53 +01:00
parent 47aa53c70a
commit 75620332c7

View File

@ -182,6 +182,36 @@ UINT64 MemfsGetSystemTime(VOID)
return ((PLARGE_INTEGER)&FileTime)->QuadPart; return ((PLARGE_INTEGER)&FileTime)->QuadPart;
} }
static inline
unsigned MemfsUpperChar(unsigned c)
{
return (c - 'a' <= 'z' - 'a') ? (c & ~0x20) : c;
}
static inline
int MemfsWcsnicmp(const wchar_t *s0, const wchar_t *t0, int n)
{
/* Use fast loop for ASCII and fall back to CompareStringW for general case. */
const wchar_t *s = s0;
const wchar_t *t = t0;
int v = 0;
for (const void *e = t + n; e > (const void *)t; ++s, ++t)
{
unsigned sc = *s, tc = *t;
if (0xffffff80 & (sc | tc))
{
v = CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, s0, n, t0, n);
if (0 != v)
return v - 2;
else
return _wcsnicmp(s, t, n);
}
if (0 != (v = MemfsUpperChar(sc) - MemfsUpperChar(tc)) || !tc)
break;
}
return v;/*(0 < v) - (0 > v);*/
}
static inline static inline
int MemfsFileNameCompare(PWSTR a, int alen, PWSTR b, int blen, BOOLEAN CaseInsensitive) int MemfsFileNameCompare(PWSTR a, int alen, PWSTR b, int blen, BOOLEAN CaseInsensitive)
{ {
@ -226,13 +256,7 @@ int MemfsFileNameCompare(PWSTR a, int alen, PWSTR b, int blen, BOOLEAN CaseInsen
len = plen < qlen ? plen : qlen; len = plen < qlen ? plen : qlen;
if (CaseInsensitive) if (CaseInsensitive)
{ res = MemfsWcsnicmp(partp, partq, len);
res = CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, partp, plen, partq, qlen);
if (0 != res)
res -= 2;
else
res = _wcsnicmp(partp, partq, len);
}
else else
res = wcsncmp(partp, partq, len); res = wcsncmp(partp, partq, len);