Skip to content

Commit

Permalink
QCoreApplication: move GetCommandLine() call to winCmdArgs()
Browse files Browse the repository at this point in the history
Gets rid of one QString allocation.

Drive-by change, remove redundant inline keyword from a static helper.

Change-Id: Ie34bbc541f661ef6f07d6384e51af461f917556e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
ahmadsamir committed Nov 6, 2024
1 parent ee3933a commit 5cd6d22
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/corelib/kernel/qcoreapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const wchar_t *>(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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5cd6d22

Please sign in to comment.