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.6 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>
This commit is contained in:
parent
9cd1b8a28d
commit
35ffe8749e
@ -104,9 +104,11 @@ private:
|
|||||||
const qsizetype len = QConcatenable< QStringBuilder<A, B> >::size(*this);
|
const qsizetype len = QConcatenable< QStringBuilder<A, B> >::size(*this);
|
||||||
T s(len, Qt::Uninitialized);
|
T s(len, Qt::Uninitialized);
|
||||||
|
|
||||||
// we abuse const_cast / constData here because we know we've just
|
// Using data_ptr() here (private API) so we can bypass the
|
||||||
// allocated the data and we're the only reference count
|
// isDetached() and the replacement of a null pointer with _empty in
|
||||||
typename T::iterator d = const_cast<typename T::iterator>(s.constData());
|
// 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());
|
||||||
|
|
||||||
if constexpr (QConcatenable<QStringBuilder<A, B>>::ExactSize) {
|
if constexpr (QConcatenable<QStringBuilder<A, B>>::ExactSize) {
|
||||||
QConcatenable<QStringBuilder<A, B>>::appendTo(*this, d);
|
QConcatenable<QStringBuilder<A, B>>::appendTo(*this, d);
|
||||||
|
@ -99,8 +99,6 @@ QList<QByteArray> supportedImageFormats(Capability cap)
|
|||||||
|
|
||||||
static constexpr QByteArrayView imagePrefix() noexcept { return "image/"; }
|
static constexpr QByteArrayView imagePrefix() noexcept { return "image/"; }
|
||||||
|
|
||||||
QT_WARNING_PUSH
|
|
||||||
QT_WARNING_DISABLE_GCC("-Warray-bounds") // QTBUG-116763
|
|
||||||
QList<QByteArray> supportedMimeTypes(Capability cap)
|
QList<QByteArray> supportedMimeTypes(Capability cap)
|
||||||
{
|
{
|
||||||
QList<QByteArray> mimeTypes;
|
QList<QByteArray> mimeTypes;
|
||||||
@ -116,7 +114,6 @@ QList<QByteArray> supportedMimeTypes(Capability cap)
|
|||||||
mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end());
|
mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end());
|
||||||
return mimeTypes;
|
return mimeTypes;
|
||||||
}
|
}
|
||||||
QT_WARNING_POP
|
|
||||||
|
|
||||||
QList<QByteArray> imageFormatsForMimeType(QByteArrayView mimeType, Capability cap)
|
QList<QByteArray> imageFormatsForMimeType(QByteArrayView mimeType, Capability cap)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user