summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorck <qt-info@nokia.com>2009-07-31 12:41:45 (GMT)
committerck <qt-info@nokia.com>2009-07-31 12:41:45 (GMT)
commitc0f0e798e903c39d5f8b6dc6dd2abdfbcc8a7d93 (patch)
tree038a5d019ec3367033f9dfe3654a5f5a7ba7e957
parent7c4b1863495905c3486ea36e0d559f49c6f2ebb4 (diff)
downloadQt-c0f0e798e903c39d5f8b6dc6dd2abdfbcc8a7d93.zip
Qt-c0f0e798e903c39d5f8b6dc6dd2abdfbcc8a7d93.tar.gz
Qt-c0f0e798e903c39d5f8b6dc6dd2abdfbcc8a7d93.tar.bz2
Assistant: Performance fixes for help generator's pattern matching.
Reading a help project was unacceptably slow with pattern matching. Now we do it only for filenames that contain wildcard symbols. Also, we cache the results of QDir::entryList() calls.
-rw-r--r--tools/assistant/lib/qhelpprojectdata.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/tools/assistant/lib/qhelpprojectdata.cpp b/tools/assistant/lib/qhelpprojectdata.cpp
index 55b4ea7..5df0426 100644
--- a/tools/assistant/lib/qhelpprojectdata.cpp
+++ b/tools/assistant/lib/qhelpprojectdata.cpp
@@ -45,6 +45,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QStack>
#include <QtCore/QMap>
+#include <QtCore/QRegExp>
#include <QtCore/QVariant>
#include <QtXml/QXmlStreamReader>
@@ -75,6 +76,8 @@ private:
void readFiles();
void raiseUnknownTokenError();
void addMatchingFiles(const QString &pattern);
+
+ QMap<QString, QStringList> dirEntriesCache;
};
void QHelpProjectDataPrivate::raiseUnknownTokenError()
@@ -265,14 +268,40 @@ void QHelpProjectDataPrivate::readFiles()
// meaningful warning later.
void QHelpProjectDataPrivate::addMatchingFiles(const QString &pattern)
{
+ // The pattern matching is expensive, so we skip it if no
+ // wildcard symbols occur in the string.
+ if (!pattern.contains('?') && !pattern.contains('*')
+ && !pattern.contains('[') && !pattern.contains(']')) {
+ filterSectionList.last().addFile(pattern);
+ return;
+ }
+
QFileInfo fileInfo(rootPath + '/' + pattern);
- const QStringList &matches =
- fileInfo.dir().entryList(QStringList(fileInfo.fileName()));
- for (QStringList::ConstIterator it = matches.constBegin();
- it != matches.constEnd();
- ++it)
- filterSectionList.last().addFile(QFileInfo(pattern).dir().path() + '/' + *it);
- if (matches.empty())
+ const QDir &dir = fileInfo.dir();
+ const QString &path = dir.canonicalPath();
+
+ // QDir::entryList() is expensive, so we cache the results.
+ QMap<QString, QStringList>::ConstIterator it = dirEntriesCache.find(path);
+ const QStringList &entries = it != dirEntriesCache.constEnd() ?
+ it.value() : dir.entryList(QDir::Files);
+ if (it == dirEntriesCache.constEnd())
+ dirEntriesCache.insert(path, entries);
+
+ bool matchFound = false;
+#ifdef Q_OS_WIN
+ Qt::CaseSensitivity cs = Qt::CaseInSensitive;
+#else
+ Qt::CaseSensitivity cs = Qt::CaseSensitive;
+#endif
+ QRegExp regExp(fileInfo.fileName(), cs, QRegExp::Wildcard);
+ foreach (const QString &file, entries) {
+ if (regExp.exactMatch(file)) {
+ matchFound = true;
+ filterSectionList.last().
+ addFile(QFileInfo(pattern).dir().path() + '/' + file);
+ }
+ }
+ if (!matchFound)
filterSectionList.last().addFile(pattern);
}