more use of move and code refactor in bandwidth related code

This commit is contained in:
Alden Torres 2018-03-21 18:38:06 -04:00 committed by Arvid Norberg
parent 6b35ebb9ad
commit 7a477cd938
4 changed files with 10 additions and 11 deletions

View File

@ -63,7 +63,7 @@ struct TORRENT_EXTRA_EXPORT bandwidth_manager
// this is used by web seeds
// returns the number of bytes to assign to the peer, or 0
// if the peer's 'assign_bandwidth' callback will be called later
int request_bandwidth(std::shared_ptr<bandwidth_socket> const& peer
int request_bandwidth(std::shared_ptr<bandwidth_socket> peer
, int blk, int priority, bandwidth_channel** chan, int num_channels);
#if TORRENT_USE_INVARIANT_CHECKS

View File

@ -37,12 +37,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bandwidth_limit.hpp"
#include "libtorrent/bandwidth_socket.hpp"
#include "libtorrent/aux_/array.hpp"
namespace libtorrent {
struct TORRENT_EXTRA_EXPORT bw_request
{
bw_request(std::shared_ptr<bandwidth_socket> const& pe
bw_request(std::shared_ptr<bandwidth_socket> pe
, int blk, int prio);
std::shared_ptr<bandwidth_socket> peer;
@ -65,7 +66,7 @@ struct TORRENT_EXTRA_EXPORT bw_request
constexpr static int max_bandwidth_channels = 10;
// we don't actually support more than 10 channels per peer
bandwidth_channel* channel[max_bandwidth_channels];
aux::array<bandwidth_channel*, max_bandwidth_channels> channel{};
};
}

View File

@ -85,8 +85,8 @@ namespace libtorrent {
// non prioritized means that, if there's a line for bandwidth,
// others will cut in front of the non-prioritized peers.
// this is used by web seeds
int bandwidth_manager::request_bandwidth(std::shared_ptr<bandwidth_socket> const& peer
, int blk, int priority, bandwidth_channel** chan, int num_channels)
int bandwidth_manager::request_bandwidth(std::shared_ptr<bandwidth_socket> peer
, int const blk, int const priority, bandwidth_channel** chan, int const num_channels)
{
INVARIANT_CHECK;
if (m_abort) return 0;
@ -108,7 +108,7 @@ namespace libtorrent {
}
int k = 0;
bw_request bwr(peer, blk, priority);
bw_request bwr(std::move(peer), blk, priority);
for (int i = 0; i < num_channels; ++i)
{
if (chan[i]->need_queueing(blk))

View File

@ -38,16 +38,15 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
bw_request::bw_request(std::shared_ptr<bandwidth_socket> const& pe
bw_request::bw_request(std::shared_ptr<bandwidth_socket> pe
, int blk, int prio)
: peer(pe)
: peer(std::move(pe))
, priority(prio)
, assigned(0)
, request_size(blk)
, ttl(20)
{
TORRENT_ASSERT(priority > 0);
std::memset(channel, 0, sizeof(channel));
}
int bw_request::assign_bandwidth()
@ -62,7 +61,7 @@ namespace libtorrent {
{
if (channel[j]->throttle() == 0) continue;
if (channel[j]->tmp == 0) continue;
quota = (std::min)(int(std::int64_t(channel[j]->distribute_quota)
quota = std::min(int(std::int64_t(channel[j]->distribute_quota)
* priority / channel[j]->tmp), quota);
}
assigned += quota;
@ -72,4 +71,3 @@ namespace libtorrent {
return quota;
}
}