From f7db58335b78c296624e65ea119ef4cec6334815 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sat, 29 Mar 2025 15:51:01 +0200 Subject: [PATCH] QInternalMimeData: avoid a QString redundant allocation By using QStringView. Drive-by, explicitly use QBA::constData() to fix the build with QT_NO_CAST_FROM_BYTEARRAY. Pick-to: 6.9 6.5 Change-Id: I57bcd877048f3b9889ab8d638979f893857af396 Reviewed-by: David Faure --- src/gui/kernel/qinternalmimedata.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qinternalmimedata.cpp b/src/gui/kernel/qinternalmimedata.cpp index d33402703e9..168afae64f5 100644 --- a/src/gui/kernel/qinternalmimedata.cpp +++ b/src/gui/kernel/qinternalmimedata.cpp @@ -187,11 +187,12 @@ QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QM buf.open(QBuffer::WriteOnly); // would there not be PNG ?? image.save(&buf, "PNG"); - } else if (mimeType.startsWith("image/"_L1) && data->hasImage()) { + } else if (auto prefix = "image/"_L1; mimeType.startsWith(prefix) && data->hasImage()) { QImage image = qvariant_cast(data->imageData()); QBuffer buf(&ba); buf.open(QBuffer::WriteOnly); - image.save(&buf, mimeType.mid(mimeType.indexOf(u'/') + 1).toLatin1().toUpper()); + auto type = QStringView{mimeType}.sliced(prefix.size()); + image.save(&buf, type.toLatin1().toUpper().constData()); } } }