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 <marc.mutz@qt.io>
(cherry picked from commit 464461dea6cab1808cdba7987e50026289afae56)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Dennis Oberst 2023-07-14 10:06:36 +02:00 committed by Qt Cherry-pick Bot
parent 742dc3ff40
commit 95befb165b

View File

@ -179,13 +179,13 @@ public:
= default; = default;
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString) QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString)
void swap(QString &other) noexcept { d.swap(other.d); } 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) #if QT_DEPRECATED_SINCE(6, 4)
QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.") QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
inline qsizetype count() const { return d.size; } inline qsizetype count() const { return d.size; }
#endif #endif
inline qsizetype length() const { return d.size; } inline qsizetype length() const noexcept { return d.size; }
inline bool isEmpty() const; inline bool isEmpty() const noexcept { return d.size == 0; }
void resize(qsizetype size); void resize(qsizetype size);
void resize(qsizetype size, QChar fillChar); 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]); } { Q_ASSERT(size_t(i) < size_t(size())); return QChar(d.data()[i]); }
inline const QChar QString::operator[](qsizetype i) const inline const QChar QString::operator[](qsizetype i) const
{ Q_ASSERT(size_t(i) < size_t(size())); return QChar(d.data()[i]); } { 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 inline const QChar *QString::unicode() const
{ return data(); } { return data(); }
inline const QChar *QString::data() const inline const QChar *QString::data() const