summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-07-22 10:56:52 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-07-22 12:36:18 (GMT)
commit023f285c3ac8ea71aa8d4662242b41fb82fb7896 (patch)
tree628d661cae41fd35d52eb4387ad8b18cc98f67d3 /src/corelib/io
parent8aaf775d3746529e8efa5110673a274ac6a7f8d4 (diff)
downloadQt-023f285c3ac8ea71aa8d4662242b41fb82fb7896.zip
Qt-023f285c3ac8ea71aa8d4662242b41fb82fb7896.tar.gz
Qt-023f285c3ac8ea71aa8d4662242b41fb82fb7896.tar.bz2
QDirIterator refactoring
Name filters and resulting regular expressions are stable, no need to regenerate the latter on each iteration. Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdiriterator.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index f7df836..9dda4f6 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -119,6 +119,10 @@ public:
const QDir::Filters filters;
const QDirIterator::IteratorFlags iteratorFlags;
+#ifndef QT_NO_REGEXP
+ QVector<QRegExp> nameRegExps;
+#endif
+
QStack<QAbstractFileEngineIterator *> fileEngineIterators;
QFileInfo currentFileInfo;
QFileInfo nextFileInfo;
@@ -140,6 +144,15 @@ QDirIteratorPrivate::QDirIteratorPrivate(const QString &path, const QStringList
, filters(QDir::NoFilter == filters ? QDir::AllEntries : filters)
, iteratorFlags(flags)
{
+#ifndef QT_NO_REGEXP
+ nameRegExps.reserve(nameFilters.size());
+ for (int i = 0; i < nameFilters.size(); ++i)
+ nameRegExps.append(
+ QRegExp(nameFilters.at(i),
+ (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive,
+ QRegExp::Wildcard));
+#endif
+
// Populate fields for hasNext() and next()
pushDirectory(QFileInfo(path));
advance();
@@ -274,11 +287,11 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
// Pass all entries through name filters, except dirs if the AllDirs
if (!nameFilters.isEmpty() && !((filters & QDir::AllDirs) && fi.isDir())) {
bool matched = false;
- for (int i = 0; i < nameFilters.size(); ++i) {
- QRegExp regexp(nameFilters.at(i),
- (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive,
- QRegExp::Wildcard);
- if (regexp.exactMatch(fileName)) {
+ for (QVector<QRegExp>::const_iterator iter = nameRegExps.constBegin(),
+ end = nameRegExps.constEnd();
+ iter != end; ++iter) {
+
+ if (iter->exactMatch(fileName)) {
matched = true;
break;
}