summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-01-23 02:04:48 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-01-23 11:44:06 +0000
commit2fed43d8438b3fb751230aa2a8115de92789ccf3 (patch)
treeeed73480587bc4a3e791a558ba9f28ba7c0ccce7 /src/gui/kernel
parent81d6906ad9fa8ad3f73b151a1e8564ffaeccc3cf (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp48
1 files changed, 26 insertions, 22 deletions
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<argc; i++) {
- if (argv[i] && *argv[i] != '-') {
+ if (!argv[i])
+ continue;
+ if (*argv[i] != '-') {
argv[j++] = argv[i];
continue;
}
const bool isXcb = platformName == "xcb";
- QByteArray arg = argv[i];
- if (arg.startsWith("--"))
- arg.remove(0, 1);
- if (arg == "-platformpluginpath") {
+ const char *arg = argv[i];
+ if (arg[1] == '-') // startsWith("--")
+ ++arg;
+ if (strcmp(arg, "-platformpluginpath") == 0) {
if (++i < argc)
platformPluginPath = QString::fromLocal8Bit(argv[i]);
- } else if (arg == "-platform") {
+ } else if (strcmp(arg, "-platform") == 0) {
if (++i < argc)
platformName = argv[i];
- } else if (arg == "-platformtheme") {
+ } else if (strcmp(arg, "-platformtheme") == 0) {
if (++i < argc)
platformThemeName = QString::fromLocal8Bit(argv[i]);
- } else if (arg == "-qwindowgeometry" || (isXcb && arg == "-geometry")) {
+ } else if (strcmp(arg, "-qwindowgeometry") == 0 || (isXcb && strcmp(arg, "-geometry") == 0)) {
if (++i < argc)
windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
- } else if (arg == "-qwindowtitle" || (isXcb && arg == "-title")) {
+ } else if (strcmp(arg, "-qwindowtitle") == 0 || (isXcb && strcmp(arg, "-title") == 0)) {
if (++i < argc)
firstWindowTitle = QString::fromLocal8Bit(argv[i]);
- } else if (arg == "-qwindowicon" || (isXcb && arg == "-icon")) {
+ } else if (strcmp(arg, "-qwindowicon") == 0 || (isXcb && strcmp(arg, "-icon") == 0)) {
if (++i < argc) {
icon = QString::fromLocal8Bit(argv[i]);
}
@@ -1280,20 +1282,22 @@ void QGuiApplicationPrivate::init()
QString s;
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 == "-plugin") {
+ const char *arg = argv[i];
+ if (arg[1] == '-') // startsWith("--")
+ ++arg;
+ if (strcmp(arg, "-plugin") == 0) {
if (++i < argc)
pluginList << argv[i];
- } else if (arg == "-reverse") {
+ } else if (strcmp(arg, "-reverse") == 0) {
force_reverse = true;
#ifdef Q_OS_MAC
- } else if (arg.startsWith("-psn_")) {
+ } else if (strncmp(arg, "-psn_", 5) == 0) {
// eat "-psn_xxxx" on Mac, which is passed when starting an app from Finder.
// special hack to change working directory (for an app bundle) when running from finder
if (QDir::currentPath() == QLatin1String("/")) {
@@ -1305,7 +1309,7 @@ void QGuiApplicationPrivate::init()
}
#endif
#ifndef QT_NO_SESSIONMANAGER
- } else if (arg == "-session" && i < argc-1) {
+ } else if (strcmp(arg, "-session") == 0 && i < argc - 1) {
++i;
if (argv[i] && *argv[i]) {
session_id = QString::fromLatin1(argv[i]);
@@ -1317,11 +1321,11 @@ void QGuiApplicationPrivate::init()
is_session_restored = true;
}
#endif
- } else if (arg == "-testability") {
+ } else if (strcmp(arg, "-testability") == 0) {
loadTestability = true;
- } else if (arg.indexOf("-style=", 0) != -1) {
- s = QString::fromLocal8Bit(arg.right(arg.length() - 7).toLower());
- } else if (arg == "-style" && i < argc-1) {
+ } else if (strncmp(arg, "-style=", 7) == 0) {
+ s = QString::fromLocal8Bit(arg + 7).toLower();
+ } else if (strcmp(arg, "-style") == 0 && i < argc - 1) {
s = QString::fromLocal8Bit(argv[++i]).toLower();
} else {
argv[j++] = argv[i];