QmlProject: Don't use RegExp for simple wildcard matching

QRegExp matching is quite expensive, and has to be done for every file
in the project directory tree against all possible suffixes. Optimize
for the common case that the pattern is "*.suffix" by doing a
fileName.endsWidth(suffix) in this case.

This speeds up loading of examples/declarative/declarative.qmlproject by
about 30%.

Reviewed-by: Christian Kamm
This commit is contained in:
Kai Koehne
2010-10-21 08:30:53 +02:00
parent ac263ef261
commit c4ca0060e3
3 changed files with 71 additions and 17 deletions

View File

@@ -208,6 +208,35 @@ void tst_FileFormat::testFileFilter()
qDebug() << project->files().toSet() << expectedFiles.toSet();
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
// use wildcards
//
projectFile = QLatin1String(
"import QmlProject 1.0\n"
"Project {\n"
" ImageFiles {\n"
" filter: \"?mage.[gf]if\"\n"
" }\n"
"}\n");
{
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine);
component.setData(projectFile.toUtf8(), QUrl());
if (!component.isReady())
qDebug() << component.errorString();
QVERIFY(component.isReady());
QmlProjectItem *project = qobject_cast<QmlProjectItem*>(component.create());
QVERIFY(project);
project->setSourceDirectory(testDataDir);
QStringList expectedFiles(QStringList() << testDataDir + "/image.gif");
qDebug() << project->files().toSet() << expectedFiles.toSet();
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
}
void tst_FileFormat::testMatchesFile()
@@ -269,8 +298,9 @@ void tst_FileFormat::testLibraryPaths()
project->setSourceDirectory(testDataDir);
QStringList expectedPaths(QStringList() << "../otherLibrary"
<< "library");
QStringList expectedPaths(QStringList() << SRCDIR "/otherLibrary"
<< SRCDIR "/data/library");
qDebug() << expectedPaths << project->importPaths();
QCOMPARE(project->importPaths().toSet(), expectedPaths.toSet());
}
}