QImageReader::read(): fetch filename once
The code in the Q_TRACE_ENABLED case was doing the same sort of qobject_cast that is done in the fileName() accessor; so it's both a code deduplication and an optimization to get the filename into a local variable once, and use it both for tracing and for the @Nx suffix check below. Task-number: QTBUG-100578 Change-Id: Id7bde4ddbab38e20694c09cc7b412fec091672de Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
2da00bfc3a
commit
21ceefacdf
@ -1246,11 +1246,9 @@ bool QImageReader::read(QImage *image)
|
|||||||
d->handler->setOption(QImageIOHandler::Quality, d->quality);
|
d->handler->setOption(QImageIOHandler::Quality, d->quality);
|
||||||
|
|
||||||
// read the image
|
// read the image
|
||||||
|
QString filename = fileName();
|
||||||
if (Q_TRACE_ENABLED(QImageReader_read_before_reading)) {
|
if (Q_TRACE_ENABLED(QImageReader_read_before_reading)) {
|
||||||
QString fileName = QStringLiteral("unknown");
|
Q_TRACE(QImageReader_read_before_reading, this, filename.isEmpty() ? u"unknown"_qs : filename);
|
||||||
if (QFile *file = qobject_cast<QFile *>(d->device))
|
|
||||||
fileName = file->fileName();
|
|
||||||
Q_TRACE(QImageReader_read_before_reading, this, fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool result = d->handler->read(image);
|
const bool result = d->handler->read(image);
|
||||||
@ -1317,7 +1315,7 @@ bool QImageReader::read(QImage *image)
|
|||||||
// successful read; check for "@Nx" file name suffix and set device pixel ratio.
|
// successful read; check for "@Nx" file name suffix and set device pixel ratio.
|
||||||
static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
|
static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
|
||||||
if (!disableNxImageLoading) {
|
if (!disableNxImageLoading) {
|
||||||
const QByteArray suffix = QFileInfo(fileName()).baseName().right(3).toLatin1();
|
const QByteArray suffix = QFileInfo(filename).baseName().right(3).toLatin1();
|
||||||
if (suffix.length() == 3 && suffix[0] == '@' && suffix[1] >= '2' && suffix[1] <= '9' && suffix[2] == 'x')
|
if (suffix.length() == 3 && suffix[0] == '@' && suffix[1] >= '2' && suffix[1] <= '9' && suffix[2] == 'x')
|
||||||
image->setDevicePixelRatio(suffix[1] - '0');
|
image->setDevicePixelRatio(suffix[1] - '0');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user