diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 9c46ea0efbc..0230b5a7844 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -857,6 +857,8 @@ # if _MSC_VER < 1936 # define Q_COMPILER_LACKS_THREE_WAY_COMPARE_SYMMETRY # endif +// QTBUG-124376: MSVC is slow at compiling qstrnlen() +# define Q_COMPILER_SLOW_QSTRNLEN_COMPILATION # endif /* __cplusplus */ #endif // defined(Q_CC_MSVC) && !defined(Q_CC_CLANG) diff --git a/src/corelib/text/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h index 3b9d8f3ccaf..41c607b857e 100644 --- a/src/corelib/text/qstringalgorithms.h +++ b/src/corelib/text/qstringalgorithms.h @@ -174,12 +174,21 @@ lengthHelperContainer(const Char (&str)[N]) return lengthHelperContainerLoop(str); } +inline qsizetype qstrnlen_helper(const char *str, size_t maxlen) +{ +#if !defined(Q_COMPILER_SLOW_QSTRNLEN_COMPILATION) + return qstrnlen(str, maxlen); +#else + return strnlen_s(str, maxlen); +#endif +} + template [[nodiscard]] constexpr inline std::enable_if_t lengthHelperContainer(const Char (&str)[N]) { #ifdef QT_SUPPORTS_IS_CONSTANT_EVALUATED if (!q20::is_constant_evaluated()) - return qstrnlen(reinterpret_cast(str), N); + return qstrnlen_helper(reinterpret_cast(str), N); #endif return lengthHelperContainerLoop(str);