diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 75e04f295..e542cb687 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -3818,18 +3818,6 @@ static void pumpAllPeers(tr_peerMgr* mgr) } } -static void queuePulseForeach(void* vtor) -{ - auto* tor = static_cast(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); + } + } } } diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 3e7a369a1..3fa26aed9 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -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_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) diff --git a/libtransmission/session.h b/libtransmission/session.h index 516a78b19..7b23691ea 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -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_sessionGetNextQueuedTorrents(tr_session* session, tr_direction dir, size_t numwanted); int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction);