From c74cba1117355a6312b1f0cc815efa4cdea4bbfa Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 9 Feb 2025 11:27:24 -0800 Subject: [PATCH] QLibraryInfo: use fewer QFileInfo in finding qt.conf This is hot code, run early in the application's life, usually as a result of the first qDebug() because QLoggingRegistry wants to find qtlogging.ini. So let's not use QFileInfo, which allocates memory, just to do string manipulation. These are always filesystem paths. See commit d59e640c868f3db2d661970f3d34a22013d49053 for a similar change in findConfiguration(). Pick-to: 6.9 6.8 Change-Id: I012daf4a3aa2ebc2c5abfffd2ef7ceac1df2626d Reviewed-by: Ahmad Samir --- src/corelib/global/qlibraryinfo.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 5f6042be29d..f6164213b0e 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -14,7 +14,7 @@ #include "qcoreapplication.h" -#include "private/qglobal_p.h" +#include "private/qfilesystementry_p.h" #include "archdetect.cpp" #include "qconfig.cpp" @@ -122,11 +122,11 @@ static std::unique_ptr findConfiguration() } #endif if (QCoreApplication::instance()) { - QDir pwd(QCoreApplication::applicationDirPath()); - qtconfig = pwd.filePath(u"qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf"_s); + QString pwd = QCoreApplication::applicationDirPath(); + qtconfig = pwd + u"/qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf"_s; if (QFile::exists(qtconfig)) return std::make_unique(qtconfig, QSettings::IniFormat); - qtconfig = pwd.filePath("qt.conf"_L1); + qtconfig = pwd + u"/qt.conf"; if (QFile::exists(qtconfig)) return std::make_unique(qtconfig, QSettings::IniFormat); } @@ -604,22 +604,26 @@ static QVariant libraryPathToValue(QLibraryInfo::LibraryPath loc) QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, UsageMode usageMode) { + using FromInternalPath = QFileSystemEntry::FromInternalPath; const QLibraryInfo::LibraryPath loc = p; QList ret; bool fromConf = false; + bool pathsAreAbsolute = true; #if QT_CONFIG(settings) if (havePaths()) { fromConf = true; QVariant value = libraryPathToValue(loc); if (value.isValid()) { - if (auto *asList = get_if>(&value)) ret = std::move(*asList); else ret = QList({ std::move(value).toString()}); - for (qsizetype i = 0, end = ret.size(); i < end; ++i) + for (qsizetype i = 0, end = ret.size(); i < end; ++i) { ret[i] = normalizePath(ret[i]); + pathsAreAbsolute = pathsAreAbsolute + && QFileSystemEntry(ret[i], FromInternalPath{}).isAbsolute(); + } } } #endif // settings @@ -640,10 +644,13 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, noConfResult = QString::fromLocal8Bit(path); #endif } - if (!noConfResult.isEmpty()) + if (!noConfResult.isEmpty()) { + pathsAreAbsolute = pathsAreAbsolute + && QFileSystemEntry(noConfResult, FromInternalPath{}).isAbsolute(); ret.push_back(std::move(noConfResult)); + } } - if (ret.isEmpty()) + if (ret.isEmpty() || pathsAreAbsolute) return ret; QString baseDir; @@ -654,7 +661,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, baseDir = QLibraryInfoPrivate::path(QLibraryInfo::PrefixPath, usageMode); } for (qsizetype i = 0, end = ret.size(); i < end; ++i) - if (QDir::isRelativePath(ret[i])) + if (QFileSystemEntry(ret[i], FromInternalPath{}).isRelative()) ret[i] = QDir::cleanPath(baseDir + u'/' + std::move(ret[i])); return ret; }