summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-02-08 21:01:24 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-04-12 18:26:55 +0000
commit21ceefacdfbab381d416aa1dc894c60595ee6b88 (patch)
tree85887f1811367accc218720bfcf719f7c9968b66 /src/gui/image
parent2da00bfc3a4361eb1bf2e008ddaceb215c63934d (diff)
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>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qimagereader.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index fe0c01e54c..83d3784005 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -1246,11 +1246,9 @@ bool QImageReader::read(QImage *image)
d->handler->setOption(QImageIOHandler::Quality, d->quality);
// read the image
+ QString filename = fileName();
if (Q_TRACE_ENABLED(QImageReader_read_before_reading)) {
- QString fileName = QStringLiteral("unknown");
- if (QFile *file = qobject_cast<QFile *>(d->device))
- fileName = file->fileName();
- Q_TRACE(QImageReader_read_before_reading, this, fileName);
+ Q_TRACE(QImageReader_read_before_reading, this, filename.isEmpty() ? u"unknown"_qs : filename);
}
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.
static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
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')
image->setDevicePixelRatio(suffix[1] - '0');
}