From 78fcbed6f2976992967e55963639e1278291d68a Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 30 Sep 2021 17:47:08 +0200 Subject: [PATCH] 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. --- src/util.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index b2fb04299..969266b4a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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) {