From bf1fd733d075a99153c9f4412c015bf528eb6516 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 29 Jul 2021 16:19:07 +0200 Subject: [PATCH] Revert "Extend the fast path of fish_wcstod" This breaks in comma-using locales (like my own de_DE.UTF-8), because it still uses the locale-dependent strtod, which will then refuse to read 1234.567 Using strtod_l (not in POSIX, I think?) might help, but might also be a lot slower. Let's revert this for now and figure out if that is workable. This reverts commit fba86fb82105e65b0b8bef8f1e1d258cfc2f08dd. --- src/wutil.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wutil.cpp b/src/wutil.cpp index 0fee1658e..b9601ba06 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -711,13 +711,14 @@ unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr, int /// Like wcstod(), but wcstod() is enormously expensive on some platforms so this tries to have a /// fast path. double fish_wcstod(const wchar_t *str, wchar_t **endptr) { - // The "fast path." If we're all ASCII, use strtod(). + // The "fast path." If we're all ASCII and we fit inline, use strtod(). char narrow[128]; size_t len = std::wcslen(str); size_t len_plus_0 = 1 + len; - auto is_ascii = [](wchar_t c) { return 0 <= c && c <= 127; }; - if (len_plus_0 <= sizeof narrow && std::all_of(str, str + len, is_ascii)) { + auto is_digit = [](wchar_t c) { return '0' <= c && c <= '9'; }; + if (len_plus_0 <= sizeof narrow && std::all_of(str, str + len, is_digit)) { // Fast path. Copy the string into a local buffer and run strtod() on it. + // We can ignore the locale-taking version because we are limited to ASCII digits. std::copy(str, str + len_plus_0, narrow); char *narrow_endptr = nullptr; double ret = strtod(narrow, endptr ? &narrow_endptr : nullptr);