QmlJS: std::set instead of QList

This reduces the CPU time of Export::visibleInVContext() from 50% to 15%
on Windows, when switching files.

Change-Id: Iff82924c47d1b696c9d3d7ca40f49d9d02bcb3e6
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2022-11-23 09:32:45 +01:00
parent 910a8864dc
commit d0a07dcacb
7 changed files with 18 additions and 10 deletions

View File

@@ -123,7 +123,8 @@ Link::Link(const Snapshot &snapshot, const ViewerContext &vContext, const Librar
{
d->m_valueOwner = new ValueOwner;
d->m_snapshot = snapshot;
d->m_importPaths = vContext.paths;
const QList<Utils::FilePath> list(vContext.paths.begin(), vContext.paths.end());
d->m_importPaths = list;
d->m_applicationDirectories = vContext.applicationDirectories;
d->m_builtins = builtins;
d->m_vContext = vContext;

View File

@@ -63,8 +63,8 @@ static const char *qtQuickUISuffix = "ui.qml";
static void maybeAddPath(ViewerContext &context, const Utils::FilePath &path)
{
if (!path.isEmpty() && !context.paths.contains(path))
context.paths.append(path);
if (!path.isEmpty() && !context.paths.count(path) > 0)
context.paths.insert(path);
}
static QList<Utils::FilePath> environmentImportPaths()

View File

@@ -8,6 +8,8 @@
#include <QStringList>
#include <set>
namespace QmlJS {
struct QMLJS_EXPORT ViewerContext
@@ -21,7 +23,7 @@ struct QMLJS_EXPORT ViewerContext
};
QStringList selectors;
QList<Utils::FilePath> paths;
std::set<Utils::FilePath> paths;
QList<Utils::FilePath> applicationDirectories;
Dialect language = Dialect::Qml;
Flags flags = AddAllPaths;

View File

@@ -149,7 +149,7 @@ static QString qualifiedTypeNameForContext(const ObjectValue *objectValue,
if (!cImport.valid())
break;
for (const Export &e : std::as_const(cImport.possibleExports)) {
if (e.pathRequired.isEmpty() || vContext.paths.contains(e.pathRequired)) {
if (e.pathRequired.isEmpty() || vContext.paths.count(e.pathRequired) > 0) {
switch (e.exportName.type) {
case ImportType::Library:
{

View File

@@ -1005,8 +1005,10 @@ QString RewriterView::pathForImport(const Import &import)
QStringList RewriterView::importDirectories() const
{
return Utils::transform(m_textToModelMerger->vContext().paths,
[](const Utils::FilePath &p) { return p.toString(); });
const QList<Utils::FilePath> list(m_textToModelMerger->vContext().paths.begin(),
m_textToModelMerger->vContext().paths.end());
return Utils::transform(list, [](const Utils::FilePath &p) { return p.toString(); });
}
QSet<QPair<QString, QString> > RewriterView::qrcMapping() const

View File

@@ -281,7 +281,7 @@ void ModelManager::delayedInitialization()
ViewerContext qbsVContext;
qbsVContext.language = Dialect::QmlQbs;
qbsVContext.paths.append(ICore::resourcePath("qbs"));
qbsVContext.paths.insert(ICore::resourcePath("qbs"));
setDefaultVContext(qbsVContext);
}

View File

@@ -58,7 +58,7 @@ void scanDirectory(const QString &dir)
ModelManagerInterface::instance(), false);
ModelManagerInterface::instance()->test_joinAllThreads();
ViewerContext vCtx;
vCtx.paths.append(dirPath);
vCtx.paths.insert(dirPath);
Snapshot snap = ModelManagerInterface::instance()->snapshot();
ImportDependencies *iDeps = snap.importDependencies();
@@ -176,7 +176,10 @@ void tst_ImportCheck::test()
ModelManagerInterface::instance(), false);
ModelManagerInterface::instance()->test_joinAllThreads();
ViewerContext vCtx;
vCtx.paths.append(pathPaths);
for (const Utils::FilePath &path : pathPaths)
vCtx.paths.insert(path);
Snapshot snap = ModelManagerInterface::instance()->snapshot();
ImportDependencies *iDeps = snap.importDependencies();