summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-10-01 00:21:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-24 15:33:19 +0100
commit432674d787124ecfd6f3e1cca74f13f0f0096e53 (patch)
tree49d1b61a9cffa7a78bf6466d20f3714f92703758 /src/widgets
parent132e812556fc171e2aec398bb077152a9aeb3aac (diff)
QWizard: Replace another pointer table with char arrays
Like in I53284066, the result of the SIGNALS() macro is handled in a switch statement, while the other two character pointers in the struct are replaced by character arrays of 'maximum occurring size'. If this looks wasteful, it really isn't: Linux AMD64 GCC 4.9-pre stripped -O2 effects: text size: -280B data size: -160B relocs: -21 When adding longer strings, compilers will warn, so this doesn't hurt maintainability, either. Change-Id: I5ac1cdffd8ac0ea0a1ede1ea4edcc6d3e22dcaa2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qwizard.cpp49
1 files changed, 34 insertions, 15 deletions
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index bf5addbc7c..0ad1dad1b8 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -129,22 +129,41 @@ static bool objectInheritsXAndXIsCloserThanY(const QObject *object, const QByteA
return false;
}
-const int NFallbackDefaultProperties = 7;
-
const struct {
- const char *className;
- const char *property;
- const char *changedSignal;
-} fallbackProperties[NFallbackDefaultProperties] = {
+ const char className[16];
+ const char property[13];
+} fallbackProperties[] = {
// If you modify this list, make sure to update the documentation (and the auto test)
- { "QAbstractButton", "checked", SIGNAL(toggled(bool)) },
- { "QAbstractSlider", "value", SIGNAL(valueChanged(int)) },
- { "QComboBox", "currentIndex", SIGNAL(currentIndexChanged(int)) },
- { "QDateTimeEdit", "dateTime", SIGNAL(dateTimeChanged(QDateTime)) },
- { "QLineEdit", "text", SIGNAL(textChanged(QString)) },
- { "QListWidget", "currentRow", SIGNAL(currentRowChanged(int)) },
- { "QSpinBox", "value", SIGNAL(valueChanged(int)) }
+ { "QAbstractButton", "checked" },
+ { "QAbstractSlider", "value" },
+ { "QComboBox", "currentIndex" },
+ { "QDateTimeEdit", "dateTime" },
+ { "QLineEdit", "text" },
+ { "QListWidget", "currentRow" },
+ { "QSpinBox", "value" },
};
+const size_t NFallbackDefaultProperties = sizeof fallbackProperties / sizeof *fallbackProperties;
+
+static const char *changed_signal(int which)
+{
+ // since it might expand to a runtime function call (to
+ // qFlagLocations()), we cannot store the result of SIGNAL() in a
+ // character array and expect it to be statically initialized. To
+ // avoid the relocations caused by a char pointer table, use a
+ // switch statement:
+ switch (which) {
+ case 0: return SIGNAL(toggled(bool));
+ case 1: return SIGNAL(valueChanged(int));
+ case 2: return SIGNAL(currentIndexChanged(int));
+ case 3: return SIGNAL(dateTimeChanged(QDateTime));
+ case 4: return SIGNAL(textChanged(QString));
+ case 5: return SIGNAL(currentRowChanged(int));
+ case 6: return SIGNAL(valueChanged(int));
+ };
+ Q_STATIC_ASSERT(7 == NFallbackDefaultProperties);
+ Q_UNREACHABLE();
+ return 0;
+}
class QWizardDefaultProperty
{
@@ -737,10 +756,10 @@ void QWizardPrivate::init()
updateButtonLayout();
- for (int i = 0; i < NFallbackDefaultProperties; ++i)
+ for (uint i = 0; i < NFallbackDefaultProperties; ++i)
defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className,
fallbackProperties[i].property,
- fallbackProperties[i].changedSignal));
+ changed_signal(i)));
}
void QWizardPrivate::reset()