From bff37a821728615d5b1c766d1fbcb80bdccfb9fd Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 14 Dec 2009 16:51:39 +0100 Subject: Assistant: Performance improvements in qhelpgenerator. - Get rid of double container lookups for conditional access. - count() == 0 => isEmpty(). Reviewed-by: kh1 --- tools/assistant/lib/qhelpgenerator.cpp | 27 +++++++++++++++------------ tools/assistant/lib/qhelpgenerator_p.h | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/assistant/lib/qhelpgenerator.cpp b/tools/assistant/lib/qhelpgenerator.cpp index 1bb4cc8..8f1b780 100644 --- a/tools/assistant/lib/qhelpgenerator.cpp +++ b/tools/assistant/lib/qhelpgenerator.cpp @@ -538,7 +538,8 @@ bool QHelpGenerator::insertFiles(const QStringList &files, const QString &rootPa } int fileId = -1; - if (!d->fileMap.contains(fileName)) { + QMap::Iterator fileMapIt = d->fileMap.find(fileName); + if (fileMapIt == d->fileMap.end()) { fileDataList.append(qCompress(data)); fileNameData.name = fileName; @@ -552,18 +553,20 @@ bool QHelpGenerator::insertFiles(const QStringList &files, const QString &rootPa ++tableFileId; } else { - fileId = d->fileMap.value(fileName); + fileId = fileMapIt.value(); + QSet &fileFilterSet = d->fileFilterMap[fileId]; + QSet &tmpFileFilterSet = tmpFileFilterMap[fileId]; foreach (const int &filter, filterAtts) { - if (!d->fileFilterMap.value(fileId).contains(filter) - && !tmpFileFilterMap.value(fileId).contains(filter)) { - d->fileFilterMap[fileId].insert(filter); - tmpFileFilterMap[fileId].insert(filter); + if (!fileFilterSet.contains(filter) + && !tmpFileFilterSet.contains(filter)) { + fileFilterSet.insert(filter); + tmpFileFilterSet.insert(filter); } } } } - if (tmpFileFilterMap.count()) { + if (!tmpFileFilterMap.isEmpty()) { d->query->exec(QLatin1String("BEGIN")); QMap >::const_iterator it = tmpFileFilterMap.constBegin(); while (it != tmpFileFilterMap.constEnd()) { @@ -626,8 +629,7 @@ bool QHelpGenerator::registerCustomFilter(const QString &filterName, while (d->query->next()) { attributeMap.insert(d->query->value(1).toString(), d->query->value(0).toInt()); - if (idsToInsert.contains(d->query->value(1).toString())) - idsToInsert.removeAll(d->query->value(1).toString()); + idsToInsert.removeAll(d->query->value(1).toString()); } foreach (QString id, idsToInsert) { @@ -675,7 +677,7 @@ bool QHelpGenerator::registerCustomFilter(const QString &filterName, return true; } -bool QHelpGenerator::insertKeywords(const QList keywords, +bool QHelpGenerator::insertKeywords(const QList &keywords, const QStringList &filterAttributes) { if (!d->query) @@ -717,8 +719,9 @@ bool QHelpGenerator::insertKeywords(const QList keywords, if (fName.startsWith(QLatin1String("./"))) fName = fName.mid(2); - if (d->fileMap.contains(fName)) - fileId = d->fileMap.value(fName); + QMap::ConstIterator it = d->fileMap.find(fName); + if (it != d->fileMap.end()) + fileId = it.value(); else fileId = 1; diff --git a/tools/assistant/lib/qhelpgenerator_p.h b/tools/assistant/lib/qhelpgenerator_p.h index 77189b0..de991e7 100644 --- a/tools/assistant/lib/qhelpgenerator_p.h +++ b/tools/assistant/lib/qhelpgenerator_p.h @@ -97,7 +97,7 @@ private: const QStringList &filterAttribs, bool forceUpdate = false); bool registerVirtualFolder(const QString &folderName, const QString &ns); bool insertFilterAttributes(const QStringList &attributes); - bool insertKeywords(const QList keywords, + bool insertKeywords(const QList &keywords, const QStringList &filterAttributes); bool insertFiles(const QStringList &files, const QString &rootPath, const QStringList &filterAttributes); -- cgit v0.12