wcsfilecmp: Skip towlower/upper if unnecessary

Also for the glob version, because this is just a performance thing.

Makes `echo **` 20% faster - 100ms to 80ms for the fish repo.

This also applies to the future `path` builtin.

Still not a speed demon, but this is a very very easy win.

Now we probably gotta do globbing all in string instead of wcs2stringing ourselves to death.
This commit is contained in:
Fabian Homborg 2021-09-30 17:47:08 +02:00
parent 4ffabd44be
commit 78fcbed6f2

View File

@ -62,6 +62,13 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) {
if (retval || *a == 0 || *b == 0) break;
}
// Fast path: Skip towupper.
if (*a == *b) {
a++;
b++;
continue;
}
wint_t al = towupper(*a);
wint_t bl = towupper(*b);
// Sort dashes after Z - see #5634
@ -115,6 +122,13 @@ int wcsfilecmp_glob(const wchar_t *a, const wchar_t *b) {
if (retval || *a == 0 || *b == 0) break;
}
// Fast path: Skip towlower.
if (*a == *b) {
a++;
b++;
continue;
}
wint_t al = towlower(*a);
wint_t bl = towlower(*b);
if (al < bl) {