refactor: remove unused tr_torrent fields (#3013)

* refactor: remove unused field tr_torrent.prefetchMagnetMetadata

* refactor: remove unused field tr_torrent.dhtAnnounce6InProgress

* refactor: remove unused field tr_torrent.dhtAnnounceInProgress

* refactor: fold etaULSpeed and etaDLSpeed into one field

* refactor: re-arrange fields to avoid padding
This commit is contained in:
Charles Kerr 2022-04-28 11:52:07 -05:00 committed by GitHub
parent 5e769fbc55
commit a400682247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 43 deletions

View File

@ -252,8 +252,8 @@ private:
std::vector<tr_peerIo*>& peer_pool);
mutable std::array<Band, 2> band_ = {};
Bandwidth* parent_ = nullptr;
std::vector<Bandwidth*> children_;
Bandwidth* parent_ = nullptr;
tr_peerIo* peer_ = nullptr;
tr_priority_t priority_ = 0;
};

View File

@ -96,7 +96,6 @@ public:
[[nodiscard]] bool isValid() const;
private:
std::vector<uint8_t> flags_;
[[nodiscard]] size_t countFlags() const noexcept;
[[nodiscard]] size_t countFlags(size_t begin, size_t end) const noexcept;
@ -120,6 +119,8 @@ private:
void incrementTrueCount(size_t inc) noexcept;
void decrementTrueCount(size_t dec) noexcept;
std::vector<uint8_t> flags_;
size_t bit_count_ = 0;
size_t true_count_ = 0;

View File

@ -837,8 +837,6 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
if (!tor->hasMetainfo() && !doStart)
{
tor->prefetchMagnetMetadata = true;
auto opts = torrent_start_opts{};
opts.bypass_queue = true;
opts.has_local_data = has_local_data;
@ -1094,30 +1092,30 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
switch (s->activity)
{
/* etaXLSpeed exists because if we use the piece speed directly,
/* etaSpeed exists because if we use the piece speed directly,
* brief fluctuations cause the ETA to jump all over the place.
* so, etaXLSpeed is a smoothed-out version of the piece speed
* to dampen the effect of fluctuations */
case TR_STATUS_DOWNLOAD:
if (tor->etaDLSpeedCalculatedAt + 800 < now)
if (tor->etaSpeedCalculatedAt + 800 < now)
{
tor->etaDLSpeed_Bps = tor->etaDLSpeedCalculatedAt + 4000 < now ?
tor->etaSpeed_Bps = tor->etaSpeedCalculatedAt + 4000 < now ?
pieceDownloadSpeed_Bps : /* if no recent previous speed, no need to smooth */
(tor->etaDLSpeed_Bps * 4.0 + pieceDownloadSpeed_Bps) / 5.0; /* smooth across 5 readings */
tor->etaDLSpeedCalculatedAt = now;
(tor->etaSpeed_Bps * 4.0 + pieceDownloadSpeed_Bps) / 5.0; /* smooth across 5 readings */
tor->etaSpeedCalculatedAt = now;
}
if (s->leftUntilDone > s->desiredAvailable && tor->webseedCount() < 1)
{
s->eta = TR_ETA_NOT_AVAIL;
}
else if (tor->etaDLSpeed_Bps == 0)
else if (tor->etaSpeed_Bps == 0)
{
s->eta = TR_ETA_UNKNOWN;
}
else
{
s->eta = s->leftUntilDone / tor->etaDLSpeed_Bps;
s->eta = s->leftUntilDone / tor->etaSpeed_Bps;
}
s->etaIdle = TR_ETA_NOT_AVAIL;
@ -1130,27 +1128,27 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
}
else
{
if (tor->etaULSpeedCalculatedAt + 800 < now)
if (tor->etaSpeedCalculatedAt + 800 < now)
{
tor->etaULSpeed_Bps = tor->etaULSpeedCalculatedAt + 4000 < now ?
tor->etaSpeed_Bps = tor->etaSpeedCalculatedAt + 4000 < now ?
pieceUploadSpeed_Bps : /* if no recent previous speed, no need to smooth */
(tor->etaULSpeed_Bps * 4.0 + pieceUploadSpeed_Bps) / 5.0; /* smooth across 5 readings */
tor->etaULSpeedCalculatedAt = now;
(tor->etaSpeed_Bps * 4.0 + pieceUploadSpeed_Bps) / 5.0; /* smooth across 5 readings */
tor->etaSpeedCalculatedAt = now;
}
if (tor->etaULSpeed_Bps == 0)
if (tor->etaSpeed_Bps == 0)
{
s->eta = TR_ETA_UNKNOWN;
}
else
{
s->eta = seedRatioBytesLeft / tor->etaULSpeed_Bps;
s->eta = seedRatioBytesLeft / tor->etaSpeed_Bps;
}
}
{
auto seedIdleMinutes = uint16_t{};
s->etaIdle = tor->etaULSpeed_Bps < 1 && tr_torrentGetSeedIdle(tor, &seedIdleMinutes) ?
s->etaIdle = tor->etaSpeed_Bps < 1 && tr_torrentGetSeedIdle(tor, &seedIdleMinutes) ?
seedIdleMinutes * 60 - s->idleSecs :
TR_ETA_NOT_AVAIL;
}
@ -1594,7 +1592,6 @@ void tr_torrentStop(tr_torrent* tor)
tor->isRunning = false;
tor->isStopping = false;
tor->prefetchMagnetMetadata = false;
tor->setDirty();
tr_runInEventThread(tor->session, stopTorrent, tor);
}

View File

@ -611,6 +611,11 @@ public:
// TODO(ckerr): make private once some of torrent.cc's `tr_torrentFoo()` methods are member functions
tr_completion completion;
// true iff the piece was verified more recently than any of the piece's
// files' mtimes (file_mtimes_). If checked_pieces_.test(piece) is false,
// it means that piece needs to be checked before its data is used.
tr_bitfield checked_pieces_ = tr_bitfield{ 0 };
tr_file_piece_map fpm_ = tr_file_piece_map{ metainfo_ };
tr_file_priorities file_priorities_{ &fpm_ };
tr_files_wanted files_wanted_{ &fpm_ };
@ -623,11 +628,6 @@ public:
// when Transmission thinks the torrent's files were last changed
std::vector<time_t> file_mtimes_;
// true iff the piece was verified more recently than any of the piece's
// files' mtimes (file_mtimes_). If checked_pieces_.test(piece) is false,
// it means that piece needs to be checked before its data is used.
tr_bitfield checked_pieces_ = tr_bitfield{ 0 };
tr_sha1_digest_t obfuscated_hash = {};
/* If the initiator of the connection receives a handshake in which the
@ -688,8 +688,7 @@ public:
uint64_t corruptCur = 0;
uint64_t corruptPrev = 0;
uint64_t etaDLSpeedCalculatedAt = 0;
uint64_t etaULSpeedCalculatedAt = 0;
uint64_t etaSpeedCalculatedAt = 0;
tr_interned_string error_announce_url;
@ -706,8 +705,7 @@ public:
tr_stat_errtype error = TR_STAT_OK;
unsigned int etaDLSpeed_Bps = 0;
unsigned int etaULSpeed_Bps = 0;
unsigned int etaSpeed_Bps = 0;
int secondsDownloading = 0;
int secondsSeeding = 0;
@ -727,9 +725,6 @@ public:
uint16_t idleLimitMinutes = 0;
bool dhtAnnounceInProgress = false;
bool dhtAnnounce6InProgress = false;
bool finishedSeedingByIdle = false;
bool isDeleting = false;
@ -739,7 +734,6 @@ public:
bool isStopping = false;
bool startAfterVerify = false;
bool prefetchMagnetMetadata = false;
bool magnetVerify = false;
private:

View File

@ -620,12 +620,10 @@ static void callback(void* /*ignore*/, int event, unsigned char const* info_hash
if (event == DHT_EVENT_SEARCH_DONE)
{
tr_logAddTraceTor(tor, "IPv4 DHT announce done");
tor->dhtAnnounceInProgress = false;
}
else
{
tr_logAddTraceTor(tor, "IPv6 DHT announce done");
tor->dhtAnnounce6InProgress = false;
}
}
}
@ -690,15 +688,6 @@ static AnnounceResult tr_dhtAnnounce(tr_torrent* tor, int af, bool announce)
tr_dhtPrintableStatus(status),
numnodes));
if (af == AF_INET)
{
tor->dhtAnnounceInProgress = true;
}
else
{
tor->dhtAnnounce6InProgress = true;
}
return AnnounceResult::OK;
}