From fe63c8ad327d7cc4ee28cf5d64c79871bb90f76f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 4 Oct 2021 18:40:40 -0500 Subject: [PATCH] Shadow/override iswdigit instead of changing it at individual call sites 1ab81ab90d1a408702e11f081fdaaafa30636c31 removed one usage of iswdigit() but there are others; more importantly, the knowledge that iswdigit() is slow isn't preserved anywhere apart from the git history, so there's nothing to prevent its use from creeping back into the codebase. Another alternative is to blacklist iswdigit() (shadow it with a function of the same name that throws a static_assert) but if we're going to shadow it anyway, might as well make it useful. --- src/common.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/common.h b/src/common.h index 2b81dfbce..04775df06 100644 --- a/src/common.h +++ b/src/common.h @@ -699,4 +699,12 @@ const T *get_by_sorted_name(const wcstring &name, const T (&vals)[N]) { return get_by_sorted_name(name.c_str(), vals); } +/// As established in 1ab81ab90d1a408702e11f081fdaaafa30636c31, iswdigit() is very slow under glibc, +/// and does nothing more than establish whether or not the single specified character is in the +/// range ('0','9'). +__attribute__((always_inline)) +bool inline iswdigit(const wchar_t c) { + return c >= L'0' && c <= L'9'; +} + #endif // FISH_COMMON_H