Commit 56f952de authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

improve performance for loading large projects

parent 52da27e6
......@@ -180,7 +180,7 @@ bool KateProject::load(const QVariantMap &globalProject, bool force)
return true;
}
void KateProject::loadProjectDone(const KateProjectSharedQStandardItem &topLevel, KateProjectSharedQMapStringItem file2Item)
void KateProject::loadProjectDone(const KateProjectSharedQStandardItem &topLevel, KateProjectSharedQHashStringItem file2Item)
{
m_model.clear();
m_model.invisibleRootItem()->appendColumn(topLevel->takeColumn(0));
......@@ -404,7 +404,7 @@ void KateProject::registerUntrackedDocument(KTextEditor::Document *document)
fileItem->setData(QVariant(true), Qt::UserRole + 3);
if (!m_file2Item) {
m_file2Item = KateProjectSharedQMapStringItem(new QMap<QString, KateProjectItem *>());
m_file2Item = KateProjectSharedQHashStringItem(new QHash<QString, KateProjectItem *>());
}
(*m_file2Item)[document->url().toLocalFile()] = fileItem;
}
......
......@@ -12,7 +12,7 @@
#include "kateprojectitem.h"
#include <KTextEditor/ModificationInterface>
#include <QDateTime>
#include <QMap>
#include <QHash>
#include <QSharedPointer>
#include <QTextDocument>
......@@ -23,8 +23,8 @@
typedef QSharedPointer<QStandardItem> KateProjectSharedQStandardItem;
Q_DECLARE_METATYPE(KateProjectSharedQStandardItem)
typedef QSharedPointer<QMap<QString, KateProjectItem *>> KateProjectSharedQMapStringItem;
Q_DECLARE_METATYPE(KateProjectSharedQMapStringItem)
typedef QSharedPointer<QHash<QString, KateProjectItem *>> KateProjectSharedQHashStringItem;
Q_DECLARE_METATYPE(KateProjectSharedQHashStringItem)
typedef QSharedPointer<KateProjectIndex> KateProjectSharedProjectIndex;
Q_DECLARE_METATYPE(KateProjectSharedProjectIndex)
......@@ -194,7 +194,7 @@ private Q_SLOTS:
* @param topLevel new toplevel element for model
* @param file2Item new file => item mapping
*/
void loadProjectDone(const KateProjectSharedQStandardItem &topLevel, KateProjectSharedQMapStringItem file2Item);
void loadProjectDone(const KateProjectSharedQStandardItem &topLevel, KateProjectSharedQHashStringItem file2Item);
/**
* Used for worker to send back the results of index loading
......@@ -264,7 +264,7 @@ private:
/**
* mapping files => items
*/
KateProjectSharedQMapStringItem m_file2Item;
KateProjectSharedQHashStringItem m_file2Item;
/**
* project index, if any
......@@ -279,7 +279,7 @@ private:
/**
* Set of existing documents for this project.
*/
QMap<KTextEditor::Document *, QString> m_documents;
QHash<KTextEditor::Document *, QString> m_documents;
/**
* Parent item for existing documents that are not in the project tree
......
......@@ -56,7 +56,7 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
, m_multiProjectGoto(false)
{
qRegisterMetaType<KateProjectSharedQStandardItem>("KateProjectSharedQStandardItem");
qRegisterMetaType<KateProjectSharedQMapStringItem>("KateProjectSharedQMapStringItem");
qRegisterMetaType<KateProjectSharedQHashStringItem>("KateProjectSharedQHashStringItem");
qRegisterMetaType<KateProjectSharedProjectIndex>("KateProjectSharedProjectIndex");
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentCreated, this, &KateProjectPlugin::slotDocumentCreated);
......
......@@ -34,21 +34,20 @@ void KateProjectWorker::run()
* then load the project recursively
*/
KateProjectSharedQStandardItem topLevel(new QStandardItem());
KateProjectSharedQMapStringItem file2Item(new QMap<QString, KateProjectItem *>());
KateProjectSharedQHashStringItem file2Item(new QHash<QString, KateProjectItem *>());
loadProject(topLevel.data(), m_projectMap, file2Item.data());
/**
* create some local backup of some data we need for further processing!
*/
QStringList files = file2Item->keys();
emit loadDone(topLevel, file2Item);
const QStringList files = file2Item->keys();
Q_EMIT loadDone(topLevel, file2Item);
// trigger index loading, will internally handle enable/disabled
loadIndex(files, m_force);
}
void KateProjectWorker::loadProject(QStandardItem *parent, const QVariantMap &project, QMap<QString, KateProjectItem *> *file2Item)
void KateProjectWorker::loadProject(QStandardItem *parent, const QVariantMap &project, QHash<QString, KateProjectItem *> *file2Item)
{
/**
* recurse to sub-projects FIRST
......@@ -88,7 +87,7 @@ void KateProjectWorker::loadProject(QStandardItem *parent, const QVariantMap &pr
* @param path current path we need item for
* @return correct parent item for given path, will reuse existing ones
*/
static QStandardItem *directoryParent(QMap<QString, QStandardItem *> &dir2Item, QString path)
static QStandardItem *directoryParent(QHash<QString, QStandardItem *> &dir2Item, QString path)
{
/**
* throw away simple /
......@@ -100,23 +99,25 @@ static QStandardItem *directoryParent(QMap<QString, QStandardItem *> &dir2Item,
/**
* quick check: dir already seen?
*/
if (dir2Item.contains(path)) {
return dir2Item[path];
const auto existingIt = dir2Item.find(path);
if (existingIt != dir2Item.end()) {
return existingIt.value();
}
/**
* else: construct recursively
*/
int slashIndex = path.lastIndexOf(QLatin1Char('/'));
const int slashIndex = path.lastIndexOf(QLatin1Char('/'));
/**
* no slash?
* simple, no recursion, append new item toplevel
*/
if (slashIndex < 0) {
dir2Item[path] = new KateProjectItem(KateProjectItem::Directory, path);
dir2Item[QString()]->appendRow(dir2Item[path]);
return dir2Item[path];
const auto item = new KateProjectItem(KateProjectItem::Directory, path);
dir2Item[path] = item;
dir2Item[QString()]->appendRow(item);
return item;
}
/**
......@@ -135,12 +136,13 @@ static QStandardItem *directoryParent(QMap<QString, QStandardItem *> &dir2Item,
/**
* else: recurse on left side
*/
dir2Item[path] = new KateProjectItem(KateProjectItem::Directory, rightPart);
directoryParent(dir2Item, leftPart)->appendRow(dir2Item[path]);
return dir2Item[path];
const auto item = new KateProjectItem(KateProjectItem::Directory, rightPart);
dir2Item[path] = item;
directoryParent(dir2Item, leftPart)->appendRow(item);
return item;
}
void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QMap<QString, KateProjectItem *> *file2Item)
void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QHash<QString, KateProjectItem *> *file2Item)
{
QDir dir(m_baseDir);
if (!dir.cd(filesEntry[QStringLiteral("directory")].toString())) {
......@@ -158,7 +160,7 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
/**
* construct paths first in tree and items in a map
*/
QMap<QString, QStandardItem *> dir2Item;
QHash<QString, QStandardItem *> dir2Item;
dir2Item[QString()] = parent;
QList<QPair<QStandardItem *, QStandardItem *>> item2ParentPath;
for (const QString &filePath : files) {
......
......@@ -11,7 +11,7 @@
#include "kateproject.h"
#include "kateprojectitem.h"
#include <QMap>
#include <QHash>
#include <QRunnable>
#include <QStandardItemModel>
......@@ -29,14 +29,14 @@ public:
/**
* Type for QueuedConnection
*/
typedef QMap<QString, KateProjectItem *> MapString2Item;
typedef QHash<QString, KateProjectItem *> MapString2Item;
explicit KateProjectWorker(const QString &baseDir, const QString &indexDir, const QVariantMap &projectMap, bool force);
void run() override;
Q_SIGNALS:
void loadDone(KateProjectSharedQStandardItem topLevel, KateProjectSharedQMapStringItem file2Item);
void loadDone(KateProjectSharedQStandardItem topLevel, KateProjectSharedQHashStringItem file2Item);
void loadIndexDone(KateProjectSharedProjectIndex index);
private:
......@@ -47,7 +47,7 @@ private:
* @param project variant map for this group
* @param file2Item mapping file => item, will be filled
*/
void loadProject(QStandardItem *parent, const QVariantMap &project, QMap<QString, KateProjectItem *> *file2Item);
void loadProject(QStandardItem *parent, const QVariantMap &project, QHash<QString, KateProjectItem *> *file2Item);
/**
* Load one files entry in the current parent item.
......@@ -55,7 +55,7 @@ private:
* @param filesEntry one files entry specification to load
* @param file2Item mapping file => item, will be filled
*/
void loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QMap<QString, KateProjectItem *> *file2Item);
void loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QHash<QString, KateProjectItem *> *file2Item);
/**
* Load index for whole project.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment