mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
refactor: use std::vector in tr_sessionGetNextQueuedTorrents (#1858)
This commit is contained in:
parent
27068cb4a6
commit
20b5a8c62b
3 changed files with 12 additions and 24 deletions
|
@ -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)
|
||||
{
|
||||
TR_ASSERT(tr_isSession(session));
|
||||
|
@ -3837,13 +3825,17 @@ static void queuePulse(tr_session* session, tr_direction 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);
|
||||
|
||||
tr_ptrArrayDestruct(&torrents, nullptr);
|
||||
if (tor->queue_started_callback != nullptr)
|
||||
{
|
||||
(*tor->queue_started_callback)(tor, tor->queue_started_user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2963,7 +2963,7 @@ int tr_sessionGetAntiBruteForceThreshold(tr_session const* session)
|
|||
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_isDirection(direction));
|
||||
|
@ -2991,11 +2991,7 @@ void tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction direction
|
|||
candidates.resize(num_wanted);
|
||||
}
|
||||
|
||||
// add them to the return array
|
||||
for (auto* candidate : candidates)
|
||||
{
|
||||
tr_ptrArrayAppend(setme, candidate);
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir)
|
||||
|
|
|
@ -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);
|
||||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue