mirror of
https://github.com/transmission/transmission.git
synced 2026-02-15 07:26:49 +00:00
refactor: convert tr_bandwidth::RateControl::newest_ to unsigned (#8094)
This commit is contained in:
@@ -39,18 +39,18 @@ Speed tr_bandwidth::get_speed(RateControl& r, unsigned int interval_msec, uint64
|
|||||||
uint64_t bytes = 0U;
|
uint64_t bytes = 0U;
|
||||||
uint64_t const cutoff = now - interval_msec;
|
uint64_t const cutoff = now - interval_msec;
|
||||||
|
|
||||||
for (int i = r.newest_; r.date_[i] > cutoff;)
|
for (auto i = r.newest_; r.date_[i] > cutoff;)
|
||||||
{
|
{
|
||||||
bytes += r.size_[i];
|
bytes += r.size_[i];
|
||||||
|
|
||||||
if (--i == -1)
|
if (--i >= HistorySize) // overflowed below zero
|
||||||
{
|
{
|
||||||
i = HistorySize - 1; /* circular history */
|
i = HistorySize - 1U; // circular history
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == r.newest_)
|
if (i == r.newest_)
|
||||||
{
|
{
|
||||||
break; /* we've come all the way around */
|
break; // we've come all the way around
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ void tr_bandwidth::notify_bandwidth_consumed_bytes(uint64_t const now, RateContr
|
|||||||
{
|
{
|
||||||
if (++r.newest_ == HistorySize)
|
if (++r.newest_ == HistorySize)
|
||||||
{
|
{
|
||||||
r.newest_ = 0;
|
r.newest_ = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.date_[r.newest_] = now;
|
r.date_[r.newest_] = now;
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ private:
|
|||||||
std::array<size_t, HistorySize> size_;
|
std::array<size_t, HistorySize> size_;
|
||||||
uint64_t cache_time_;
|
uint64_t cache_time_;
|
||||||
Speed cache_val_;
|
Speed cache_val_;
|
||||||
int newest_;
|
size_t newest_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Band
|
struct Band
|
||||||
|
|||||||
Reference in New Issue
Block a user