mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Improve Torrent content tree structure creation
Use QHash to cache folder items. PR #16183.
This commit is contained in:
parent
43c427b253
commit
0cc318664d
@ -498,6 +498,7 @@ void TorrentContentModel::setupModelData(const BitTorrent::AbstractFileStorage &
|
|||||||
m_filesIndex.reserve(filesCount);
|
m_filesIndex.reserve(filesCount);
|
||||||
|
|
||||||
TorrentContentModelFolder *currentParent;
|
TorrentContentModelFolder *currentParent;
|
||||||
|
QHash<TorrentContentModelFolder *, QHash<QString, TorrentContentModelFolder *>> folderMap;
|
||||||
// Iterate over files
|
// Iterate over files
|
||||||
for (int i = 0; i < filesCount; ++i)
|
for (int i = 0; i < filesCount; ++i)
|
||||||
{
|
{
|
||||||
@ -510,13 +511,14 @@ void TorrentContentModel::setupModelData(const BitTorrent::AbstractFileStorage &
|
|||||||
|
|
||||||
for (const QStringView pathPart : asConst(pathFolders))
|
for (const QStringView pathPart : asConst(pathFolders))
|
||||||
{
|
{
|
||||||
const QString folderPath = pathPart.toString();
|
const QString folderName = pathPart.toString();
|
||||||
TorrentContentModelFolder *newParent = currentParent->childFolderWithName(folderPath);
|
TorrentContentModelFolder *&newParent = folderMap[currentParent][folderName];
|
||||||
if (!newParent)
|
if (!newParent)
|
||||||
{
|
{
|
||||||
newParent = new TorrentContentModelFolder(folderPath, currentParent);
|
newParent = new TorrentContentModelFolder(folderName, currentParent);
|
||||||
currentParent->appendChild(newParent);
|
currentParent->appendChild(newParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentParent = newParent;
|
currentParent = newParent;
|
||||||
}
|
}
|
||||||
// Actually create the file
|
// Actually create the file
|
||||||
|
@ -81,17 +81,6 @@ TorrentContentModelItem *TorrentContentModelFolder::child(int row) const
|
|||||||
{
|
{
|
||||||
return m_childItems.value(row, nullptr);
|
return m_childItems.value(row, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const
|
|
||||||
{
|
|
||||||
for (TorrentContentModelItem *child : asConst(m_childItems))
|
|
||||||
{
|
|
||||||
if ((child->itemType() == FolderType) && (child->name() == name))
|
|
||||||
return static_cast<TorrentContentModelFolder *>(child);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TorrentContentModelFolder::childCount() const
|
int TorrentContentModelFolder::childCount() const
|
||||||
{
|
{
|
||||||
return m_childItems.count();
|
return m_childItems.count();
|
||||||
|
@ -59,7 +59,6 @@ public:
|
|||||||
const QVector<TorrentContentModelItem*> &children() const;
|
const QVector<TorrentContentModelItem*> &children() const;
|
||||||
void appendChild(TorrentContentModelItem *item);
|
void appendChild(TorrentContentModelItem *item);
|
||||||
TorrentContentModelItem *child(int row) const;
|
TorrentContentModelItem *child(int row) const;
|
||||||
TorrentContentModelFolder *childFolderWithName(const QString &name) const;
|
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user