summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-05-05 12:29:37 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-06-11 15:43:02 -0700
commitb1ee49b46533d39f7fabda68d0bd08a1ab130a27 (patch)
tree19ea17d7c568117d31fbd244b23cdcc5ccf19086 /src/corelib/text/qstring.cpp
parent95e6fac0a5a1eee3aa23e4da0a93c6c25e32fb98 (diff)
Q{Any,}StringView: optimize lengthHelperContainer for the runtime
Deduplicate it in the process by moving to qstringalgorithms.h. In non-constexpr contexts, both GCC and Clang were giving up in pre-calculating the length if the UTF-16 string literal was too big. For the old code, that was 14 and 16 characters respectively. That number can be raised by adding some Q_ALWAYS_INLINE and (for GCC's case), replacing std::char_traits::find() with std::find(). If that limit is exceeded, we call the newly introduced qustrnlen() function. qustrnlen() is just qustrchr(), like qstrnlen() is just memchr(). But it is introduced as a separate function so we could change implementation if we ever wished to, plus QStringView is only forward-declared at this point. Change-Id: Ieab617d69f3b4b54ab30fffd175c560d926db1c3 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 1fae9ef07af..15cf40ef885 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -698,6 +698,11 @@ qsizetype QtPrivate::qustrlen(const char16_t *str) noexcept
return result;
}
+qsizetype QtPrivate::qustrnlen(const char16_t *str, qsizetype maxlen) noexcept
+{
+ return qustrchr({ str, maxlen }, u'\0') - str;
+}
+
/*!
* \internal
*