summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qanystringview.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-05-05 10:45:19 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-06-11 15:43:00 -0700
commit631901f6d1da84ded3528d26f00ea5fa3bfbf6a2 (patch)
tree118d00d165caf48c0601d9e638e41b1f9b27e96e /src/corelib/text/qanystringview.h
parent60f34fc9e368010a5eaae920e5e306e59abf8e73 (diff)
Q{Any,}StringView: remove the GCC-specific compile-time content
Because GCC isn't really working them out at compile time. First, for both lengthHelperPointer(), they don't get called on string literals such as return QStringView(u"Hello"); because the type hasn't decayed to a pointer, but is instead a char16_t[6]. No one writes constexpr auto str = u"Hello"; return QStringView(str); Second, even when you do write that, GCC is emitting the code to search for the null or non-ASCII byte at runtime, instead of pre-calculating it. That's not worth it because the code is not vectorized, even at -O3 and with a long string. Instead, let it get the length at runtime with QtPrivate::qustrlen(), which has vector code. Drive-by fix the QAnyStringView::lengthPointerHelper() to be constexpr, avoiding the same GCC warning that was fixed for QStringView in commit 4fd4082c3ab682f14911e6308ec5ccb400de34f9. Change-Id: Ieab617d69f3b4b54ab30fffd175c505cb66eac02 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/text/qanystringview.h')
-rw-r--r--src/corelib/text/qanystringview.h19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h
index 4be8910cf6..c2a4b9ad09 100644
--- a/src/corelib/text/qanystringview.h
+++ b/src/corelib/text/qanystringview.h
@@ -101,18 +101,13 @@ private:
static constexpr bool isAsciiOnlyCharsAtCompileTime(Char *str, qsizetype sz) noexcept
{
// do not perform check if not at compile time
-#if !(defined(__cpp_lib_is_constant_evaluated) || defined(Q_CC_GNU))
+#if !defined(__cpp_lib_is_constant_evaluated)
Q_UNUSED(str);
Q_UNUSED(sz);
return false;
#else
-# if defined(__cpp_lib_is_constant_evaluated)
if (!std::is_constant_evaluated())
return false;
-# elif defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
- if (!str || !__builtin_constant_p(*str))
- return false;
-# endif
if constexpr (sizeof(Char) != sizeof(char)) {
Q_UNUSED(str);
Q_UNUSED(sz);
@@ -140,15 +135,11 @@ private:
}
template <typename Char>
- static qsizetype lengthHelperPointer(const Char *str) noexcept
+ static constexpr qsizetype lengthHelperPointer(const Char *str) noexcept
{
-#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
- if (__builtin_constant_p(*str)) {
- qsizetype result = 0;
- while (*str++ != u'\0')
- ++result;
- return result;
- }
+#ifdef __cpp_lib_is_constant_evaluated
+ if (std::is_constant_evaluated())
+ return qsizetype(std::char_traits<Char>::length(str));
#endif
if constexpr (sizeof(Char) == sizeof(char16_t))
return QtPrivate::qustrlen(reinterpret_cast<const char16_t*>(str));