QStringBuilder: use data_ptr().data() instead of constData()

As the comment says, this allows us to skip the check for non-detached
strings and for null ones. We know that the one we've just created isn't
either, so long as len != 0. All QConcatenable::appendTo() calls do
nothing if len == 0, including not calling memcpy() at all.

Moreover, because it no longer references the QByteArray::_empty
variable, the GCC -Warray-bounds warning should be gone too.

Task-number: QTBUG-116763
Pick-to: 6.5
Change-Id: Ica7a43f6147b49c187ccfffd179eba2897ce2aff
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit 06c724881c4227acf308e54ebd3db8235bb6b740)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 35ffe8749e7af31b70e3e7b993dceab75aa95633)
This commit is contained in:
Thiago Macieira 2023-12-07 18:34:02 -08:00
parent 502da47bc0
commit 95017918c3
2 changed files with 6 additions and 6 deletions

View File

@ -76,9 +76,12 @@ private:
const qsizetype len = QConcatenable< QStringBuilder<A, B> >::size(*this);
T s(len, Qt::Uninitialized);
// we abuse const_cast / constData here because we know we've just
// allocated the data and we're the only reference count
typename T::iterator d = const_cast<typename T::iterator>(s.constData());
// Using data_ptr() here (private API) so we can bypass the
// isDetached() and the replacement of a null pointer with _empty in
// both QString and QByteArray's data() and constData(). The result is
// the same if len != 0.
auto d = reinterpret_cast<typename T::iterator>(s.data_ptr().data());
typename T::const_iterator const start = d;
QConcatenable< QStringBuilder<A, B> >::appendTo(*this, d);

View File

@ -97,8 +97,6 @@ QList<QByteArray> supportedImageFormats(Capability cap)
return formats;
}
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Warray-bounds") // QTBUG-116763
QList<QByteArray> supportedMimeTypes(Capability cap)
{
QList<QByteArray> mimeTypes;
@ -114,7 +112,6 @@ QList<QByteArray> supportedMimeTypes(Capability cap)
mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end());
return mimeTypes;
}
QT_WARNING_POP
QList<QByteArray> imageFormatsForMimeType(const QByteArray &mimeType, Capability cap)
{