From 5cd6d227f986e62e63876d1c21562c9fa677f092 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 4 Nov 2024 18:49:07 +0200 Subject: [PATCH] QCoreApplication: move GetCommandLine() call to winCmdArgs() Gets rid of one QString allocation. Drive-by change, remove redundant inline keyword from a static helper. Change-Id: Ie34bbc541f661ef6f07d6384e51af461f917556e Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 45189115ab4..2620dd15c98 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2544,11 +2544,16 @@ qint64 QCoreApplication::applicationPid() } #ifdef Q_OS_WIN -static inline QStringList winCmdArgs(const QString &cmdLine) +static QStringList winCmdArgs() { + // On Windows, it is possible to pass Unicode arguments on + // the command line, but we don't implement any of the wide + // entry-points (wmain/wWinMain), so get the arguments from + // the Windows API instead of using argv. Note that we only + // do this when argv were not modified by the user in main(). QStringList result; int size; - if (wchar_t **argv = CommandLineToArgvW(reinterpret_cast(cmdLine.utf16()), &size)) { + if (wchar_t **argv = CommandLineToArgvW(GetCommandLine(), &size)) { result.reserve(size); wchar_t **argvEnd = argv + size; for (wchar_t **a = argv; a < argvEnd; ++a) @@ -2608,13 +2613,7 @@ QStringList QCoreApplication::arguments() #if defined(Q_OS_WIN) const bool argsModifiedByUser = d->origArgv == nullptr; if (!argsModifiedByUser) { - // On Windows, it is possible to pass Unicode arguments on - // the command line, but we don't implement any of the wide - // entry-points (wmain/wWinMain), so get the arguments from - // the Windows API instead of using argv. Note that we only - // do this when argv were not modified by the user in main(). - QString cmdline = QString::fromWCharArray(GetCommandLine()); - QStringList commandLineArguments = winCmdArgs(cmdline); + QStringList commandLineArguments = winCmdArgs(); // Even if the user didn't modify argv before passing them // on to QCoreApplication, derived QApplications might have.