From 1ab81ab90d1a408702e11f081fdaaafa30636c31 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 1 Oct 2021 15:43:58 +0200 Subject: [PATCH] wcsfilecmp: Don't use iswdigit For some godforsaken reason it's slow on glibc Like, actually, this manages to somehow make "echo **" 10% faster now? The spec says this matches 0 through 9 always, so this is safe. We also use this logic in a variety of other places already. --- src/util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 969266b4a..022cc6068 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -55,7 +55,7 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) { int retval = 0; // assume the strings will be equal while (*a && *b) { - if (iswdigit(*a) && iswdigit(*b)) { + if (*a >= L'0' && *a <= L'9' && *b >= L'0' && *b <= L'9') { retval = wcsfilecmp_leading_digits(&a, &b); // If we know the strings aren't logically equal or we've reached the end of one or both // strings we can stop iterating over the chars in each string. @@ -115,7 +115,7 @@ int wcsfilecmp_glob(const wchar_t *a, const wchar_t *b) { int retval = 0; // assume the strings will be equal while (*a && *b) { - if (iswdigit(*a) && iswdigit(*b)) { + if (*a >= L'0' && *a <= L'9' && *b >= L'0' && *b <= L'9') { retval = wcsfilecmp_leading_digits(&a, &b); // If we know the strings aren't logically equal or we've reached the end of one or both // strings we can stop iterating over the chars in each string.