dbus: Use QList::reserve(), reduces reallocations.

Change-Id: I5d60220c4d3014067a45a3d3553f0523c9fc7c74
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Sérgio Martins 2015-06-22 18:12:40 +01:00
parent 19e63a207f
commit a4d3af9614
3 changed files with 10 additions and 2 deletions

View File

@ -317,7 +317,9 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
} }
QVariantList args; QVariantList args;
for (int i = 1; i < types.count(); ++i) const int numTypes = types.count();
args.reserve(numTypes - 1);
for (int i = 1; i < numTypes; ++i)
args << QVariant(types.at(i), argv[i]); args << QVariant(types.at(i), argv[i]);
// now emit the signal with all the information // now emit the signal with all the information

View File

@ -952,14 +952,19 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
} }
// output arguments // output arguments
const int numMetaTypes = metaTypes.count();
QVariantList outputArgs; QVariantList outputArgs;
void *null = 0; void *null = 0;
if (metaTypes[0] != QMetaType::Void && metaTypes[0] != QMetaType::UnknownType) { if (metaTypes[0] != QMetaType::Void && metaTypes[0] != QMetaType::UnknownType) {
outputArgs.reserve(numMetaTypes - i + 1);
QVariant arg(metaTypes[0], null); QVariant arg(metaTypes[0], null);
outputArgs.append( arg ); outputArgs.append( arg );
params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()); params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData());
} else {
outputArgs.reserve(numMetaTypes - i);
} }
for ( ; i < metaTypes.count(); ++i) {
for ( ; i < numMetaTypes; ++i) {
QVariant arg(metaTypes[i], null); QVariant arg(metaTypes[i], null);
outputArgs.append( arg ); outputArgs.append( arg );
params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData())); params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()));

View File

@ -278,6 +278,7 @@ int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv)
// we will assume that the input arguments were passed correctly // we will assume that the input arguments were passed correctly
QVariantList args; QVariantList args;
args.reserve(inputTypesCount);
int i = 1; int i = 1;
for ( ; i <= inputTypesCount; ++i) for ( ; i <= inputTypesCount; ++i)
args << QVariant(inputTypes[i], argv[i]); args << QVariant(inputTypes[i], argv[i]);