Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
56f952de
Commit
56f952de
authored
Feb 02, 2021
by
Christoph Cullmann
🐮
Browse files
improve performance for loading large projects
parent
52da27e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
addons/project/kateproject.cpp
View file @
56f952de
...
...
@@ -180,7 +180,7 @@ bool KateProject::load(const QVariantMap &globalProject, bool force)
return
true
;
}
void
KateProject
::
loadProjectDone
(
const
KateProjectSharedQStandardItem
&
topLevel
,
KateProjectSharedQ
Map
StringItem
file2Item
)
void
KateProject
::
loadProjectDone
(
const
KateProjectSharedQStandardItem
&
topLevel
,
KateProjectSharedQ
Hash
StringItem
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
=
KateProjectSharedQ
Map
StringItem
(
new
Q
Map
<
QString
,
KateProjectItem
*>
());
m_file2Item
=
KateProjectSharedQ
Hash
StringItem
(
new
Q
Hash
<
QString
,
KateProjectItem
*>
());
}
(
*
m_file2Item
)[
document
->
url
().
toLocalFile
()]
=
fileItem
;
}
...
...
addons/project/kateproject.h
View file @
56f952de
...
...
@@ -12,7 +12,7 @@
#include "kateprojectitem.h"
#include <KTextEditor/ModificationInterface>
#include <QDateTime>
#include <Q
Map
>
#include <Q
Hash
>
#include <QSharedPointer>
#include <QTextDocument>
...
...
@@ -23,8 +23,8 @@
typedef
QSharedPointer
<
QStandardItem
>
KateProjectSharedQStandardItem
;
Q_DECLARE_METATYPE
(
KateProjectSharedQStandardItem
)
typedef
QSharedPointer
<
Q
Map
<
QString
,
KateProjectItem
*>>
KateProjectSharedQ
Map
StringItem
;
Q_DECLARE_METATYPE
(
KateProjectSharedQ
Map
StringItem
)
typedef
QSharedPointer
<
Q
Hash
<
QString
,
KateProjectItem
*>>
KateProjectSharedQ
Hash
StringItem
;
Q_DECLARE_METATYPE
(
KateProjectSharedQ
Hash
StringItem
)
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
,
KateProjectSharedQ
Map
StringItem
file2Item
);
void
loadProjectDone
(
const
KateProjectSharedQStandardItem
&
topLevel
,
KateProjectSharedQ
Hash
StringItem
file2Item
);
/**
* Used for worker to send back the results of index loading
...
...
@@ -264,7 +264,7 @@ private:
/**
* mapping files => items
*/
KateProjectSharedQ
Map
StringItem
m_file2Item
;
KateProjectSharedQ
Hash
StringItem
m_file2Item
;
/**
* project index, if any
...
...
@@ -279,7 +279,7 @@ private:
/**
* Set of existing documents for this project.
*/
Q
Map
<
KTextEditor
::
Document
*
,
QString
>
m_documents
;
Q
Hash
<
KTextEditor
::
Document
*
,
QString
>
m_documents
;
/**
* Parent item for existing documents that are not in the project tree
...
...
addons/project/kateprojectplugin.cpp
View file @
56f952de
...
...
@@ -56,7 +56,7 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
,
m_multiProjectGoto
(
false
)
{
qRegisterMetaType
<
KateProjectSharedQStandardItem
>
(
"KateProjectSharedQStandardItem"
);
qRegisterMetaType
<
KateProjectSharedQ
Map
StringItem
>
(
"KateProjectSharedQ
Map
StringItem"
);
qRegisterMetaType
<
KateProjectSharedQ
Hash
StringItem
>
(
"KateProjectSharedQ
Hash
StringItem"
);
qRegisterMetaType
<
KateProjectSharedProjectIndex
>
(
"KateProjectSharedProjectIndex"
);
connect
(
KTextEditor
::
Editor
::
instance
()
->
application
(),
&
KTextEditor
::
Application
::
documentCreated
,
this
,
&
KateProjectPlugin
::
slotDocumentCreated
);
...
...
addons/project/kateprojectworker.cpp
View file @
56f952de
...
...
@@ -34,21 +34,20 @@ void KateProjectWorker::run()
* then load the project recursively
*/
KateProjectSharedQStandardItem
topLevel
(
new
QStandardItem
());
KateProjectSharedQ
Map
StringItem
file2Item
(
new
Q
Map
<
QString
,
KateProjectItem
*>
());
KateProjectSharedQ
Hash
StringItem
file2Item
(
new
Q
Hash
<
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
,
Q
Map
<
QString
,
KateProjectItem
*>
*
file2Item
)
void
KateProjectWorker
::
loadProject
(
QStandardItem
*
parent
,
const
QVariantMap
&
project
,
Q
Hash
<
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
(
Q
Map
<
QString
,
QStandardItem
*>
&
dir2Item
,
QString
path
)
static
QStandardItem
*
directoryParent
(
Q
Hash
<
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
,
Q
Map
<
QString
,
KateProjectItem
*>
*
file2Item
)
void
KateProjectWorker
::
loadFilesEntry
(
QStandardItem
*
parent
,
const
QVariantMap
&
filesEntry
,
Q
Hash
<
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
*/
Q
Map
<
QString
,
QStandardItem
*>
dir2Item
;
Q
Hash
<
QString
,
QStandardItem
*>
dir2Item
;
dir2Item
[
QString
()]
=
parent
;
QList
<
QPair
<
QStandardItem
*
,
QStandardItem
*>>
item2ParentPath
;
for
(
const
QString
&
filePath
:
files
)
{
...
...
addons/project/kateprojectworker.h
View file @
56f952de
...
...
@@ -11,7 +11,7 @@
#include "kateproject.h"
#include "kateprojectitem.h"
#include <Q
Map
>
#include <Q
Hash
>
#include <QRunnable>
#include <QStandardItemModel>
...
...
@@ -29,14 +29,14 @@ public:
/**
* Type for QueuedConnection
*/
typedef
Q
Map
<
QString
,
KateProjectItem
*>
MapString2Item
;
typedef
Q
Hash
<
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
,
KateProjectSharedQ
Map
StringItem
file2Item
);
void
loadDone
(
KateProjectSharedQStandardItem
topLevel
,
KateProjectSharedQ
Hash
StringItem
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
,
Q
Map
<
QString
,
KateProjectItem
*>
*
file2Item
);
void
loadProject
(
QStandardItem
*
parent
,
const
QVariantMap
&
project
,
Q
Hash
<
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
,
Q
Map
<
QString
,
KateProjectItem
*>
*
file2Item
);
void
loadFilesEntry
(
QStandardItem
*
parent
,
const
QVariantMap
&
filesEntry
,
Q
Hash
<
QString
,
KateProjectItem
*>
*
file2Item
);
/**
* Load index for whole project.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment