diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 1e1a8c9c5e4..b7b33fa3ac1 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -495,12 +495,19 @@ public: // -1 to deal with the NUL terminator return Data::maxSize() - 1; } - inline qsizetype size() const noexcept { return d.size; } + constexpr qsizetype size() const noexcept + { +#if __has_cpp_attribute(assume) + constexpr size_t MaxSize = maxSize(); + [[assume(size_t(d.size) <= MaxSize)]]; +#endif + return d.size; + } #if QT_DEPRECATED_SINCE(6, 4) QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.") - inline qsizetype count() const noexcept { return size(); } + constexpr qsizetype count() const noexcept { return size(); } #endif - inline qsizetype length() const noexcept { return size(); } + constexpr qsizetype length() const noexcept { return size(); } QT_CORE_INLINE_SINCE(6, 4) bool isNull() const noexcept; diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index b36ac709a2c..c1875688a48 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -232,12 +232,19 @@ public: // -1 to deal with the NUL terminator return Data::maxSize() - 1; } - inline qsizetype size() const noexcept { return d.size; } + constexpr qsizetype size() const noexcept + { +#if __has_cpp_attribute(assume) + constexpr size_t MaxSize = maxSize(); + [[assume(size_t(d.size) <= MaxSize)]]; +#endif + 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; } + constexpr qsizetype count() const { return size(); } #endif - inline qsizetype length() const noexcept { return d.size; } + constexpr qsizetype length() const noexcept { return size(); } inline bool isEmpty() const noexcept { return d.size == 0; } void resize(qsizetype size); void resize(qsizetype size, QChar fillChar); diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 81139c5891b..c9b931e420a 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -438,9 +438,16 @@ public: #endif // Q_QDOC static constexpr qsizetype maxSize() { return Data::maxSize(); } - qsizetype size() const noexcept { return d->size; } - qsizetype count() const noexcept { return size(); } - qsizetype length() const noexcept { return size(); } + constexpr qsizetype size() const noexcept + { +#if __has_cpp_attribute(assume) + constexpr size_t MaxSize = maxSize(); + [[assume(size_t(d.size) <= MaxSize)]]; +#endif + return d.size; + } + constexpr qsizetype count() const noexcept { return size(); } + constexpr qsizetype length() const noexcept { return size(); } inline bool isEmpty() const noexcept { return d->size == 0; }