uic: optimize generateMultiDirectiveBegin()

Instead of building a QMap with dummy values, just to sort the
elements of the QSet, build a QList, and sort that.

Also use QStringList::join() instead of rolling our own loop.

Change-Id: Iebb7faac8e4b72d6f71b3ab3feba7865b1a102f3
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
bb10
Marc Mutz 2016-01-25 14:10:58 +01:00
parent 1ac6644dda
commit c29d3692d7
1 changed files with 7 additions and 15 deletions

View File

@ -2488,24 +2488,16 @@ static void generateMultiDirectiveBegin(QTextStream &outputStream, const QSet<QS
if (directives.isEmpty())
return;
QMap<QString, bool> map; // bool is dummy. The idea is to sort that (always generate in the same order) by putting a set into a map
foreach (const QString &str, directives)
map.insert(str, true);
if (map.size() == 1) {
outputStream << "#ifndef " << map.constBegin().key() << endl;
if (directives.size() == 1) {
outputStream << "#ifndef " << *directives.cbegin() << endl;
return;
}
outputStream << "#if";
bool doOr = false;
foreach (const QString &str, map.keys()) {
if (doOr)
outputStream << " ||";
outputStream << " !defined(" << str << ')';
doOr = true;
}
outputStream << endl;
auto list = directives.toList();
// sort (always generate in the same order):
std::sort(list.begin(), list.end());
outputStream << "#if !defined(" << list.join(QLatin1String(") || !defined(")) << ')' << endl;
}
static void generateMultiDirectiveEnd(QTextStream &outputStream, const QSet<QString> &directives)