From 21ceefacdfbab381d416aa1dc894c60595ee6b88 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 8 Feb 2022 21:01:24 +0100 Subject: [PATCH] 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 --- src/gui/image/qimagereader.cpp | 8 +++----- 1 file 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(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'); }