Skip to content
Snippets Groups Projects
Commit 2e8ec2f9 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Fix performance problem in Snapshot.

Don't use QMultiHash::values(key), it rebuilds the values list from
scratch for each lookup.

Reviewed-by: Roberto Raggi
parent 3499fcb1
No related branches found
No related tags found
No related merge requests found
...@@ -339,7 +339,7 @@ void Snapshot::insert(const Document::Ptr &document) ...@@ -339,7 +339,7 @@ void Snapshot::insert(const Document::Ptr &document)
const QString path = document->path(); const QString path = document->path();
remove(fileName); remove(fileName);
_documentsByPath.insert(path, document); _documentsByPath[path].append(document);
_documents.insert(fileName, document); _documents.insert(fileName, document);
} }
} }
...@@ -353,7 +353,12 @@ void Snapshot::remove(const QString &fileName) ...@@ -353,7 +353,12 @@ void Snapshot::remove(const QString &fileName)
{ {
Document::Ptr doc = _documents.value(fileName); Document::Ptr doc = _documents.value(fileName);
if (!doc.isNull()) { if (!doc.isNull()) {
_documentsByPath.remove(doc->path(), doc); const QString &path = doc->path();
QList<Document::Ptr> docs = _documentsByPath.value(path);
docs.removeAll(doc);
_documentsByPath[path] = docs;
_documents.remove(fileName); _documents.remove(fileName);
} }
} }
...@@ -378,7 +383,7 @@ Document::Ptr Snapshot::document(const QString &fileName) const ...@@ -378,7 +383,7 @@ Document::Ptr Snapshot::document(const QString &fileName) const
QList<Document::Ptr> Snapshot::documentsInDirectory(const QString &path) const QList<Document::Ptr> Snapshot::documentsInDirectory(const QString &path) const
{ {
return _documentsByPath.values(QDir::cleanPath(path)); return _documentsByPath.value(QDir::cleanPath(path));
} }
LibraryInfo Snapshot::libraryInfo(const QString &path) const LibraryInfo Snapshot::libraryInfo(const QString &path) const
......
...@@ -146,7 +146,7 @@ class QMLJS_EXPORT Snapshot ...@@ -146,7 +146,7 @@ class QMLJS_EXPORT Snapshot
{ {
typedef QHash<QString, Document::Ptr> _Base; typedef QHash<QString, Document::Ptr> _Base;
QHash<QString, Document::Ptr> _documents; QHash<QString, Document::Ptr> _documents;
QMultiHash<QString, Document::Ptr> _documentsByPath; QHash<QString, QList<Document::Ptr> > _documentsByPath;
QHash<QString, LibraryInfo> _libraries; QHash<QString, LibraryInfo> _libraries;
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment