summaryrefslogtreecommitdiff
path: root/tools/assistant/lib/qhelpprojectdata.cpp
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-08-04 10:33:52 +0200
committerJason Barron <jbarron@trolltech.com>2009-08-04 11:02:17 +0200
commit4aafbd6222e7aeafd59a4a4356ba8c53b2bfa1d1 (patch)
treeb34985c5716d98f01b9f36fd4a98f2ac9710099f /tools/assistant/lib/qhelpprojectdata.cpp
parenta0df97c03f26a38af17a42fb44ad6910536c8857 (diff)
parent2076f150995e541308b1d8da936b3e12ab68b886 (diff)
downloadqt4-tools-4aafbd6222e7aeafd59a4a4356ba8c53b2bfa1d1.tar.gz
Merge commit 'qt/master-stable'
Conflicts: config.tests/unix/openssl/openssl.pri demos/embedded/embedded.pro examples/itemviews/chart/chart.pro examples/network/network.pro examples/painting/painterpaths/painterpaths.pro examples/threads/mandelbrot/mandelbrot.pro qmake/project.cpp src/3rdparty/libtiff/libtiff/tif_config.h src/corelib/arch/arch.pri src/corelib/global/qglobal.cpp src/corelib/kernel/kernel.pri src/corelib/kernel/qcore_unix_p.h src/corelib/kernel/qobject.cpp src/corelib/thread/qthread_unix.cpp src/corelib/tools/qsharedpointer_impl.h src/corelib/tools/tools.pri src/gui/kernel/qaction.h src/gui/kernel/qapplication.cpp src/gui/painting/qregion.h src/gui/widgets/qlineedit.cpp src/gui/widgets/qlineedit_p.h src/network/socket/qnativesocketengine_unix.cpp tests/auto/qdir/tst_qdir.cpp tests/auto/qdiriterator/tst_qdiriterator.cpp tests/auto/qhttp/qhttp.pro tests/auto/qline/qline.pro tests/auto/qnetworkreply/tst_qnetworkreply.cpp tests/auto/qresourceengine/qresourceengine.pro tests/auto/qsharedpointer/qsharedpointer.pro tests/auto/qstring/qstring.pro tests/auto/qtcpsocket/qtcpsocket.pro tests/auto/qtcpsocket/tst_qtcpsocket.cpp
Diffstat (limited to 'tools/assistant/lib/qhelpprojectdata.cpp')
-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 55b4ea755e..9412f1c524 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);
}