From 9dde61f4b3519b4de5b83fab463c8d8136baf5b6 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 30 Nov 2015 15:26:16 +0100 Subject: Optimize qt_findAtNxFile by reducing the amount of allocations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I94a2b40933f9469f509a4cc54d68138696704ba2 Reviewed-by: Morten Johan Sørvig --- src/gui/image/qicon.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index dc6cbfed1f..d9e1347e4b 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Olivier Goffart ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -1400,15 +1401,15 @@ QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRati if (disableNxImageLoading) return baseFileName; - QString atNx = QLatin1String("@%1x"); int dotIndex = baseFileName.lastIndexOf(QLatin1Char('.')); if (dotIndex == -1) /* no dot */ dotIndex = baseFileName.size(); /* append */ + QString atNxfileName = baseFileName; + atNxfileName.insert(dotIndex, QLatin1String("@2x")); // Check for @Nx, ..., @3x, @2x file versions, - for (int n = qCeil(targetDevicePixelRatio); n > 1; --n) { - QString atNxfileName = baseFileName; - atNxfileName.insert(dotIndex, atNx.arg(n)); + for (int n = qMin(qCeil(targetDevicePixelRatio), 9); n > 1; --n) { + atNxfileName[dotIndex + 1] = QLatin1Char('0' + n); if (QFile::exists(atNxfileName)) { if (sourceDevicePixelRatio) *sourceDevicePixelRatio = n; -- cgit v1.2.3