From d34a3536bf8bc8a2a24f5daf8b77fcda5e25d733 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 9 Feb 2025 12:32:28 -0800 Subject: [PATCH] QCoreApplication: avoid QFileInfo in applicationDirPath() QFileInfo allocates a lot of memory, so it's not very good a tool for manipulating just strings. As this function is called very early in the application's lifetime (by the first qDebug() or so), we can avoid creating the QFileInfoPrivate by going straight to QFileSystemEngine, which is what QFileInfo::path() would have done: QString QFileInfo::path() const { Q_D(const QFileInfo); if (d->isDefaultConstructed) return ""_L1; return d->fileEntry.path(); } Change-Id: Ie911c42577113c477aa9fffd5dcbb7e6f24af8f6 Reviewed-by: Ahmad Samir --- src/corelib/kernel/qcoreapplication.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 87d7ab434c2..f3934210797 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -2382,7 +2383,8 @@ QString QCoreApplication::applicationDirPath() return QString(); } - return QFileInfo(applicationFilePath()).path(); + QFileSystemEntry appFilePath(applicationFilePath(), QFileSystemEntry::FromInternalPath{}); + return appFilePath.isEmpty() ? QString() : appFilePath.path(); } #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN)