From ac2d063add3cd795a10c6eb3613a95f81b2be929 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 19 Apr 2020 11:12:18 +0800 Subject: [PATCH 1/2] Move initialization default values to header --- src/base/bittorrent/torrenthandleimpl.cpp | 5 ----- src/base/bittorrent/torrenthandleimpl.h | 10 +++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/base/bittorrent/torrenthandleimpl.cpp b/src/base/bittorrent/torrenthandleimpl.cpp index 409d83090..472171dfb 100644 --- a/src/base/bittorrent/torrenthandleimpl.cpp +++ b/src/base/bittorrent/torrenthandleimpl.cpp @@ -166,8 +166,6 @@ TorrentHandleImpl::TorrentHandleImpl(Session *session, const lt::torrent_handle : QObject(session) , m_session(session) , m_nativeHandle(nativeHandle) - , m_state(TorrentState::Unknown) - , m_renameCount(0) , m_useAutoTMM(params.savePath.isEmpty()) , m_name(params.name) , m_savePath(Utils::Fs::toNativePath(params.savePath)) @@ -177,10 +175,7 @@ TorrentHandleImpl::TorrentHandleImpl(Session *session, const lt::torrent_handle , m_ratioLimit(params.ratioLimit) , m_seedingTimeLimit(params.seedingTimeLimit) , m_tempPathDisabled(params.disableTempPath) - , m_fastresumeDataRejected(false) - , m_hasMissingFiles(false) , m_hasRootFolder(params.hasRootFolder) - , m_needsToSetFirstLastPiecePriority(false) { if (m_useAutoTMM) m_savePath = Utils::Fs::toNativePath(m_session->categorySavePath(m_category)); diff --git a/src/base/bittorrent/torrenthandleimpl.h b/src/base/bittorrent/torrenthandleimpl.h index 9cc139933..76738a9a9 100644 --- a/src/base/bittorrent/torrenthandleimpl.h +++ b/src/base/bittorrent/torrenthandleimpl.h @@ -298,7 +298,7 @@ namespace BitTorrent Session *const m_session; lt::torrent_handle m_nativeHandle; lt::torrent_status m_nativeStatus; - TorrentState m_state; + TorrentState m_state = TorrentState::Unknown; TorrentInfo m_torrentInfo; SpeedMonitor m_speedMonitor; @@ -308,7 +308,7 @@ namespace BitTorrent // m_moveFinishedTriggers is activated only when the following conditions are met: // all file rename jobs complete, all file move jobs complete QQueue m_moveFinishedTriggers; - int m_renameCount; + int m_renameCount = 0; // Until libtorrent provide an "old_name" field in `file_renamed_alert` // we will rely on this workaround to remove empty leftover folders @@ -325,10 +325,10 @@ namespace BitTorrent qreal m_ratioLimit; int m_seedingTimeLimit; bool m_tempPathDisabled; - bool m_fastresumeDataRejected; - bool m_hasMissingFiles; + bool m_fastresumeDataRejected = false; + bool m_hasMissingFiles = false; bool m_hasRootFolder; - bool m_needsToSetFirstLastPiecePriority; + bool m_needsToSetFirstLastPiecePriority = false; QHash m_trackerInfos; From 1b80890696628c7d96ce8d6fc046442f4d0408c2 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 19 Apr 2020 11:14:37 +0800 Subject: [PATCH 2/2] Reduce padding in class TorrentHandleImpl size is reduced from 768 bytes to 736 bytes. CreateTorrentParams size didn't change. Size numbers are from x64. --- src/base/bittorrent/torrenthandleimpl.cpp | 8 ++++---- src/base/bittorrent/torrenthandleimpl.h | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/base/bittorrent/torrenthandleimpl.cpp b/src/base/bittorrent/torrenthandleimpl.cpp index 472171dfb..53f654d1d 100644 --- a/src/base/bittorrent/torrenthandleimpl.cpp +++ b/src/base/bittorrent/torrenthandleimpl.cpp @@ -132,6 +132,8 @@ CreateTorrentParams::CreateTorrentParams(const AddTorrentParams ¶ms) , category(params.category) , tags(params.tags) , savePath(params.savePath) + , uploadLimit(params.uploadLimit) + , downloadLimit(params.downloadLimit) , disableTempPath(params.disableTempPath) , sequential(params.sequential) , firstLastPiecePriority(params.firstLastPiecePriority) @@ -144,8 +146,6 @@ CreateTorrentParams::CreateTorrentParams(const AddTorrentParams ¶ms) , paused(params.addPaused == TriStateBool::Undefined ? Session::instance()->isAddTorrentPaused() : params.addPaused == TriStateBool::True) - , uploadLimit(params.uploadLimit) - , downloadLimit(params.downloadLimit) , filePriorities(params.filePriorities) , ratioLimit(params.ignoreShareLimits ? TorrentHandleImpl::NO_RATIO_LIMIT : TorrentHandleImpl::USE_GLOBAL_RATIO) , seedingTimeLimit(params.ignoreShareLimits ? TorrentHandleImpl::NO_SEEDING_TIME_LIMIT : TorrentHandleImpl::USE_GLOBAL_SEEDING_TIME) @@ -166,16 +166,16 @@ TorrentHandleImpl::TorrentHandleImpl(Session *session, const lt::torrent_handle : QObject(session) , m_session(session) , m_nativeHandle(nativeHandle) - , m_useAutoTMM(params.savePath.isEmpty()) , m_name(params.name) , m_savePath(Utils::Fs::toNativePath(params.savePath)) , m_category(params.category) , m_tags(params.tags) - , m_hasSeedStatus(params.hasSeedStatus) , m_ratioLimit(params.ratioLimit) , m_seedingTimeLimit(params.seedingTimeLimit) + , m_hasSeedStatus(params.hasSeedStatus) , m_tempPathDisabled(params.disableTempPath) , m_hasRootFolder(params.hasRootFolder) + , m_useAutoTMM(params.savePath.isEmpty()) { if (m_useAutoTMM) m_savePath = Utils::Fs::toNativePath(m_session->categorySavePath(m_category)); diff --git a/src/base/bittorrent/torrenthandleimpl.h b/src/base/bittorrent/torrenthandleimpl.h index 76738a9a9..8b1adfbc8 100644 --- a/src/base/bittorrent/torrenthandleimpl.h +++ b/src/base/bittorrent/torrenthandleimpl.h @@ -55,12 +55,16 @@ namespace BitTorrent struct CreateTorrentParams { - bool restored = false; // is existing torrent job? + CreateTorrentParams() = default; + explicit CreateTorrentParams(const AddTorrentParams ¶ms); + // for both new and restored torrents QString name; QString category; QSet tags; QString savePath; + int uploadLimit = -1; + int downloadLimit = -1; bool disableTempPath = false; bool sequential = false; bool firstLastPiecePriority = false; @@ -69,17 +73,15 @@ namespace BitTorrent bool hasRootFolder = true; bool forced = false; bool paused = false; - int uploadLimit = -1; - int downloadLimit = -1; + bool restored = false; // is existing torrent job? + // for new torrents QVector filePriorities; QDateTime addedTime; + // for restored torrents qreal ratioLimit = TorrentHandle::USE_GLOBAL_RATIO; int seedingTimeLimit = TorrentHandle::USE_GLOBAL_SEEDING_TIME; - - CreateTorrentParams() = default; - explicit CreateTorrentParams(const AddTorrentParams ¶ms); }; enum class MoveStorageMode @@ -304,33 +306,32 @@ namespace BitTorrent InfoHash m_hash; - bool m_storageIsMoving = false; // m_moveFinishedTriggers is activated only when the following conditions are met: // all file rename jobs complete, all file move jobs complete QQueue m_moveFinishedTriggers; int m_renameCount = 0; + bool m_storageIsMoving = false; // Until libtorrent provide an "old_name" field in `file_renamed_alert` // we will rely on this workaround to remove empty leftover folders QHash> m_oldPath; - bool m_useAutoTMM; + QHash m_trackerInfos; // Persistent data QString m_name; QString m_savePath; QString m_category; QSet m_tags; - bool m_hasSeedStatus; qreal m_ratioLimit; int m_seedingTimeLimit; + bool m_hasSeedStatus; bool m_tempPathDisabled; bool m_fastresumeDataRejected = false; bool m_hasMissingFiles = false; bool m_hasRootFolder; bool m_needsToSetFirstLastPiecePriority = false; - - QHash m_trackerInfos; + bool m_useAutoTMM; bool m_unchecked = false; };