mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-05 20:51:25 -07:00
Improve resume queue load performance
PR #22831. --------- Co-authored-by: Vladimir Golovnev <glassez@yandex.ru>
This commit is contained in:
parent
ff07591a87
commit
d7a5430893
1 changed files with 13 additions and 4 deletions
|
@ -189,8 +189,13 @@ void BitTorrent::BencodeResumeDataStorage::loadQueue(const Path &queueFilename)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<TorrentID, qsizetype> registeredTorrentsIndexes;
|
||||||
|
registeredTorrentsIndexes.reserve(m_registeredTorrents.length());
|
||||||
|
for (qsizetype i = 0; i < m_registeredTorrents.length(); ++i)
|
||||||
|
registeredTorrentsIndexes.insert(m_registeredTorrents.at(i), i);
|
||||||
|
|
||||||
const QRegularExpression hashPattern {u"^([A-Fa-f0-9]{40})$"_s};
|
const QRegularExpression hashPattern {u"^([A-Fa-f0-9]{40})$"_s};
|
||||||
int start = 0;
|
qsizetype queuePos = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
const auto line = QString::fromLatin1(queueFile.readLine(lineMaxLength).trimmed());
|
const auto line = QString::fromLatin1(queueFile.readLine(lineMaxLength).trimmed());
|
||||||
|
@ -201,11 +206,15 @@ void BitTorrent::BencodeResumeDataStorage::loadQueue(const Path &queueFilename)
|
||||||
if (rxMatch.hasMatch())
|
if (rxMatch.hasMatch())
|
||||||
{
|
{
|
||||||
const auto torrentID = BitTorrent::TorrentID::fromString(rxMatch.captured(1));
|
const auto torrentID = BitTorrent::TorrentID::fromString(rxMatch.captured(1));
|
||||||
const int pos = m_registeredTorrents.indexOf(torrentID, start);
|
const qsizetype pos = registeredTorrentsIndexes.value(torrentID, -1);
|
||||||
if (pos != -1)
|
if (pos != -1)
|
||||||
{
|
{
|
||||||
std::swap(m_registeredTorrents[start], m_registeredTorrents[pos]);
|
if (pos != queuePos)
|
||||||
++start;
|
{
|
||||||
|
m_registeredTorrents.swapItemsAt(pos, queuePos);
|
||||||
|
registeredTorrentsIndexes.insert(m_registeredTorrents.at(pos), pos);
|
||||||
|
}
|
||||||
|
++queuePos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue