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 <david.faure@kdab.com>
This commit is contained in:
Ahmad Samir 2025-03-29 15:51:01 +02:00
parent 10d7de1f5c
commit f7db58335b

View File

@ -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<QImage>(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());
}
}
}