1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00

refactor: use std::vector in tr_sessionGetNextQueuedTorrents (#1858)

This commit is contained in:
Charles Kerr 2021-09-29 17:21:04 -05:00 committed by GitHub
parent 27068cb4a6
commit 20b5a8c62b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 24 deletions

View file

@ -3818,18 +3818,6 @@ static void pumpAllPeers(tr_peerMgr* mgr)
} }
} }
static void queuePulseForeach(void* vtor)
{
auto* tor = static_cast<tr_torrent*>(vtor);
tr_torrentStartNow(tor);
if (tor->queue_started_callback != nullptr)
{
(*tor->queue_started_callback)(tor, tor->queue_started_user_data);
}
}
static void queuePulse(tr_session* session, tr_direction dir) static void queuePulse(tr_session* session, tr_direction dir)
{ {
TR_ASSERT(tr_isSession(session)); TR_ASSERT(tr_isSession(session));
@ -3837,13 +3825,17 @@ static void queuePulse(tr_session* session, tr_direction dir)
if (tr_sessionGetQueueEnabled(session, dir)) if (tr_sessionGetQueueEnabled(session, dir))
{ {
auto torrents = tr_ptrArray{}; auto const n = tr_sessionCountQueueFreeSlots(session, dir);
tr_sessionGetNextQueuedTorrents(session, dir, tr_sessionCountQueueFreeSlots(session, dir), &torrents); for (auto* tor : tr_sessionGetNextQueuedTorrents(session, dir, n))
{
tr_torrentStartNow(tor);
tr_ptrArrayForeach(&torrents, queuePulseForeach); if (tor->queue_started_callback != nullptr)
{
tr_ptrArrayDestruct(&torrents, nullptr); (*tor->queue_started_callback)(tor, tor->queue_started_user_data);
}
}
} }
} }

View file

@ -2963,7 +2963,7 @@ int tr_sessionGetAntiBruteForceThreshold(tr_session const* session)
return tr_rpcGetAntiBruteForceThreshold(session->rpcServer); return tr_rpcGetAntiBruteForceThreshold(session->rpcServer);
} }
void tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction direction, size_t num_wanted, tr_ptrArray* setme) std::vector<tr_torrent*> tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction direction, size_t num_wanted)
{ {
TR_ASSERT(tr_isSession(session)); TR_ASSERT(tr_isSession(session));
TR_ASSERT(tr_isDirection(direction)); TR_ASSERT(tr_isDirection(direction));
@ -2991,11 +2991,7 @@ void tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction direction
candidates.resize(num_wanted); candidates.resize(num_wanted);
} }
// add them to the return array return candidates;
for (auto* candidate : candidates)
{
tr_ptrArrayAppend(setme, candidate);
}
} }
int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir) int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir)

View file

@ -344,7 +344,7 @@ void tr_sessionSetAltSpeed_Bps(tr_session*, tr_direction, unsigned int Bps);
bool tr_sessionGetActiveSpeedLimit_Bps(tr_session const* session, tr_direction dir, unsigned int* setme); bool tr_sessionGetActiveSpeedLimit_Bps(tr_session const* session, tr_direction dir, unsigned int* setme);
void tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction dir, size_t numwanted, tr_ptrArray* setme); std::vector<tr_torrent*> tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction dir, size_t numwanted);
int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction); int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction);