summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.h
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-02-24 15:37:59 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2022-03-02 22:22:36 +0100
commit62c7145390b0a98b83f901f193183b429df8cbf5 (patch)
tree8ea6efd0b8ca43af47ea5f8e0b7fad0c34a1612b /src/corelib/text/qstring.h
parent736213bf662b68c4e80075cef317e5a029b490dd (diff)
Fix QLatin1String(const char *) constructor to be constexpr
strlen() is not constexpr, use the QByteArrayView's lengthHelperPointer() instead. Change-Id: Ie49236edba3306e951402e6b776c15068cac0332 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.h')
-rw-r--r--src/corelib/text/qstring.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 1c95b038c6..350659ed46 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -49,6 +49,7 @@
#include <QtCore/qchar.h>
#include <QtCore/qbytearray.h>
+#include <QtCore/qbytearrayview.h>
#include <QtCore/qarraydata.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qstringliteral.h>
@@ -85,7 +86,8 @@ class QLatin1String
public:
constexpr inline QLatin1String() noexcept : m_size(0), m_data(nullptr) {}
constexpr QLatin1String(std::nullptr_t) noexcept : QLatin1String() {}
- constexpr inline explicit QLatin1String(const char *s) noexcept : m_size(s ? qsizetype(strlen(s)) : 0), m_data(s) {}
+ constexpr inline explicit QLatin1String(const char *s) noexcept
+ : m_size(s ? qsizetype(QtPrivate::lengthHelperPointer(s)) : 0), m_data(s) {}
constexpr explicit QLatin1String(const char *f, const char *l)
: QLatin1String(f, qsizetype(l - f)) {}
constexpr inline explicit QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {}