QInputDialog: use a switch instead of a string pointer table

Effects on Linux AMD64 GCC 4.9-trunk -O2 stripped release:
  text:   -72B
  data:   -64B
  relocs:  -4

Change-Id: Ie312e12ba42f58fa5dd61da1e64b9c22bf4738b2
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2013-10-08 18:08:38 +02:00
parent b52b5fa082
commit c4a2d6ca1e

View File

@ -60,25 +60,40 @@
QT_USE_NAMESPACE
enum CandidateSignal {
TextValueSelectedSignal,
IntValueSelectedSignal,
DoubleValueSelectedSignal,
AcceptedSignal,
NumCandidateSignals
};
static const char *candidateSignal(int which)
{
switch (CandidateSignal(which)) {
case TextValueSelectedSignal: return SIGNAL(textValueSelected(QString));
case IntValueSelectedSignal: return SIGNAL(intValueSelected(int));
case DoubleValueSelectedSignal: return SIGNAL(doubleValueSelected(double));
case AcceptedSignal: return SIGNAL(accepted());
case NumCandidateSignals: ; // fall through
};
Q_UNREACHABLE();
return Q_NULLPTR;
}
static const char *signalForMember(const char *member)
{
static const int NumCandidates = 4;
static const char * const candidateSignals[NumCandidates] = {
SIGNAL(textValueSelected(QString)),
SIGNAL(intValueSelected(int)),
SIGNAL(doubleValueSelected(double)),
SIGNAL(accepted())
};
QByteArray normalizedMember(QMetaObject::normalizedSignature(member));
int i = 0;
while (i < NumCandidates - 1) { // sic
if (QMetaObject::checkConnectArgs(candidateSignals[i], normalizedMember))
while (i < NumCandidateSignals - 1) { // sic
if (QMetaObject::checkConnectArgs(candidateSignal(i), normalizedMember))
break;
++i;
}
return candidateSignals[i];
return candidateSignal(i);
}
QT_BEGIN_NAMESPACE