From 2fed43d8438b3fb751230aa2a8115de92789ccf3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 23 Jan 2016 02:04:48 +0100 Subject: [PATCH] Q*Application: don't allocate memory just to compare C strings Instead of creating a QByteArray, possibly normalizing a leading '--' (one allocation, plus possibly one copy), simply use the old 'ol str(n)cmp, skipping the first character if the argument starts with '--'. It also fixes parsing of -stylesheet and other options which were erroneously parsed using indexOf() != -1, when they should have used startsWith(). Also saves 504/742/522b in text size for QtCore/QtGui/QtWidgets, resp., on optimized GCC 5.3 Linux AMD64 builds. Change-Id: Ida868badac3fb9b77285417ee537c861ccc4fc06 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.cpp | 16 +++++---- src/gui/kernel/qguiapplication.cpp | 48 +++++++++++++------------ src/widgets/kernel/qapplication.cpp | 18 +++++----- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index abc5af94cb..48d70f2747 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -182,16 +182,18 @@ void QCoreApplicationPrivate::processCommandLineArguments() { int j = argc ? 1 : 0; for (int i = 1; i < argc; ++i) { - if (argv[i] && *argv[i] != '-') { + if (!argv[i]) + continue; + if (*argv[i] != '-') { argv[j++] = argv[i]; continue; } - QByteArray arg = argv[i]; - if (arg.startsWith("--")) - arg.remove(0, 1); - if (arg.startsWith("-qmljsdebugger=")) { - qmljs_debug_arguments = QString::fromLocal8Bit(arg.right(arg.length() - 15)); - } else if (arg == "-qmljsdebugger" && i < argc - 1) { + const char *arg = argv[i]; + if (arg[1] == '-') // startsWith("--") + ++arg; + if (strncmp(arg, "-qmljsdebugger=", 15) == 0) { + qmljs_debug_arguments = QString::fromLocal8Bit(arg + 15); + } else if (strcmp(arg, "-qmljsdebugger") == 0 && i < argc - 1) { ++i; qmljs_debug_arguments = QString::fromLocal8Bit(argv[i]); } else { diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 0f015af2b9..7d469dd25e 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1181,30 +1181,32 @@ void QGuiApplicationPrivate::createPlatformIntegration() int j = argc ? 1 : 0; for (int i=1; i