qDBusInterfaceFromMetaObject: avoid quadratic complexity.

Don't use QString::prepend() in the loop. Just compose
temp string by appending, and then prepend whole temp string.

Change-Id: I6efb2d20e03f6a3526103d3a9494d5d1b0fbbf81
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Anton Kudryavtsev 2016-04-26 13:58:00 +03:00
parent d2304a28ca
commit cd1eff1e1e
1 changed files with 8 additions and 3 deletions

View File

@ -99,9 +99,14 @@ QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
if (domainName.isEmpty()) {
interface.prepend(QLatin1String("local."));
} else {
interface.reserve(interface.size() + organizationDomain.size());
for (const QStringRef &x : domainName)
interface.prepend(QLatin1Char('.')).prepend(x);
QString composedDomain;
// + 1 for additional dot, e.g. organizationDomain equals "example.com",
// then composedDomain will be equal "com.example."
composedDomain.reserve(organizationDomain.size() + 1);
for (auto it = domainName.rbegin(), end = domainName.rend(); it != end; ++it)
composedDomain += *it + QLatin1Char('.');
interface.prepend(composedDomain);
}
}
}