forked from qt-creator/qt-creator
ProjectExplorer: Speed up finding subfolder nodes
Instead of building up a temporary list and searching in there, search the children directly. Change-Id: Ibf08dad6dbbed3fbda3b93a7df311b9dd6f6e710 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -54,14 +54,6 @@
|
|||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
static FolderNode *folderNode(const FolderNode *folder, const Utils::FilePath &directory)
|
|
||||||
{
|
|
||||||
return static_cast<FolderNode *>(Utils::findOrDefault(folder->folderNodes(),
|
|
||||||
[&directory](const FolderNode *fn) {
|
|
||||||
return fn && fn->filePath() == directory;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
|
static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
|
||||||
const Utils::FilePath &directory,
|
const Utils::FilePath &directory,
|
||||||
const Utils::FilePath &overrideBaseDir,
|
const Utils::FilePath &overrideBaseDir,
|
||||||
@@ -93,7 +85,7 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
|
|||||||
foreach (const QString &part, parts) {
|
foreach (const QString &part, parts) {
|
||||||
path = path.pathAppended(part);
|
path = path.pathAppended(part);
|
||||||
// Find folder in subFolders
|
// Find folder in subFolders
|
||||||
FolderNode *next = folderNode(parent, path);
|
FolderNode *next = parent->folderNode(path);
|
||||||
if (!next) {
|
if (!next) {
|
||||||
// No FolderNode yet, so create it
|
// No FolderNode yet, so create it
|
||||||
auto tmp = factory(path);
|
auto tmp = factory(path);
|
||||||
@@ -626,6 +618,15 @@ QList<FolderNode*> FolderNode::folderNodes() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FolderNode *FolderNode::folderNode(const Utils::FilePath &directory) const
|
||||||
|
{
|
||||||
|
Node *node = Utils::findOrDefault(m_nodes, [directory](const std::unique_ptr<Node> &n) {
|
||||||
|
FolderNode *fn = n->asFolderNode();
|
||||||
|
return fn && fn->filePath() == directory;
|
||||||
|
});
|
||||||
|
return static_cast<FolderNode *>(node);
|
||||||
|
}
|
||||||
|
|
||||||
void FolderNode::addNestedNode(std::unique_ptr<FileNode> &&fileNode,
|
void FolderNode::addNestedNode(std::unique_ptr<FileNode> &&fileNode,
|
||||||
const Utils::FilePath &overrideBaseDir,
|
const Utils::FilePath &overrideBaseDir,
|
||||||
const FolderNodeFactory &factory)
|
const FolderNodeFactory &factory)
|
||||||
|
@@ -236,6 +236,8 @@ public:
|
|||||||
QList<FileNode *> fileNodes() const;
|
QList<FileNode *> fileNodes() const;
|
||||||
FileNode *fileNode(const Utils::FilePath &file) const;
|
FileNode *fileNode(const Utils::FilePath &file) const;
|
||||||
QList<FolderNode *> folderNodes() const;
|
QList<FolderNode *> folderNodes() const;
|
||||||
|
FolderNode *folderNode(const Utils::FilePath &directory) const;
|
||||||
|
|
||||||
using FolderNodeFactory = std::function<std::unique_ptr<FolderNode>(const Utils::FilePath &)>;
|
using FolderNodeFactory = std::function<std::unique_ptr<FolderNode>(const Utils::FilePath &)>;
|
||||||
void addNestedNodes(std::vector<std::unique_ptr<FileNode>> &&files,
|
void addNestedNodes(std::vector<std::unique_ptr<FileNode>> &&files,
|
||||||
const Utils::FilePath &overrideBaseDir = Utils::FilePath(),
|
const Utils::FilePath &overrideBaseDir = Utils::FilePath(),
|
||||||
|
Reference in New Issue
Block a user