From 95befb165b0395c5848285cebeab4b4592ed1144 Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Fri, 14 Jul 2023 10:06:36 +0200 Subject: [PATCH] QString: make isEmpty(), length() and size() noexcept They have no preconditions and cannot throw. As a drive-by, merge the definition of isEmpty() into its declaration. Change-Id: Ifffa0d4cb2a285bb802d39d10a757be9c31cfae1 Reviewed-by: Marc Mutz (cherry picked from commit 464461dea6cab1808cdba7987e50026289afae56) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qstring.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index e050ec356e4..f3c7ce10266 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -179,13 +179,13 @@ public: = default; QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString) void swap(QString &other) noexcept { d.swap(other.d); } - inline qsizetype size() const { return d.size; } + inline qsizetype size() const noexcept { return d.size; } #if QT_DEPRECATED_SINCE(6, 4) QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.") inline qsizetype count() const { return d.size; } #endif - inline qsizetype length() const { return d.size; } - inline bool isEmpty() const; + inline qsizetype length() const noexcept { return d.size; } + inline bool isEmpty() const noexcept { return d.size == 0; } void resize(qsizetype size); void resize(qsizetype size, QChar fillChar); @@ -1080,8 +1080,6 @@ inline const QChar QString::at(qsizetype i) const { Q_ASSERT(size_t(i) < size_t(size())); return QChar(d.data()[i]); } inline const QChar QString::operator[](qsizetype i) const { Q_ASSERT(size_t(i) < size_t(size())); return QChar(d.data()[i]); } -inline bool QString::isEmpty() const -{ return d.size == 0; } inline const QChar *QString::unicode() const { return data(); } inline const QChar *QString::data() const