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>
This commit is contained in:
parent
132e812556
commit
432674d787
@ -129,22 +129,41 @@ static bool objectInheritsXAndXIsCloserThanY(const QObject *object, const QByteA
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int NFallbackDefaultProperties = 7;
|
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
const char *className;
|
const char className[16];
|
||||||
const char *property;
|
const char property[13];
|
||||||
const char *changedSignal;
|
} fallbackProperties[] = {
|
||||||
} fallbackProperties[NFallbackDefaultProperties] = {
|
|
||||||
// If you modify this list, make sure to update the documentation (and the auto test)
|
// If you modify this list, make sure to update the documentation (and the auto test)
|
||||||
{ "QAbstractButton", "checked", SIGNAL(toggled(bool)) },
|
{ "QAbstractButton", "checked" },
|
||||||
{ "QAbstractSlider", "value", SIGNAL(valueChanged(int)) },
|
{ "QAbstractSlider", "value" },
|
||||||
{ "QComboBox", "currentIndex", SIGNAL(currentIndexChanged(int)) },
|
{ "QComboBox", "currentIndex" },
|
||||||
{ "QDateTimeEdit", "dateTime", SIGNAL(dateTimeChanged(QDateTime)) },
|
{ "QDateTimeEdit", "dateTime" },
|
||||||
{ "QLineEdit", "text", SIGNAL(textChanged(QString)) },
|
{ "QLineEdit", "text" },
|
||||||
{ "QListWidget", "currentRow", SIGNAL(currentRowChanged(int)) },
|
{ "QListWidget", "currentRow" },
|
||||||
{ "QSpinBox", "value", SIGNAL(valueChanged(int)) }
|
{ "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
|
class QWizardDefaultProperty
|
||||||
{
|
{
|
||||||
@ -737,10 +756,10 @@ void QWizardPrivate::init()
|
|||||||
|
|
||||||
updateButtonLayout();
|
updateButtonLayout();
|
||||||
|
|
||||||
for (int i = 0; i < NFallbackDefaultProperties; ++i)
|
for (uint i = 0; i < NFallbackDefaultProperties; ++i)
|
||||||
defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className,
|
defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className,
|
||||||
fallbackProperties[i].property,
|
fallbackProperties[i].property,
|
||||||
fallbackProperties[i].changedSignal));
|
changed_signal(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWizardPrivate::reset()
|
void QWizardPrivate::reset()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user