diff --git a/crates/udp/src/config.rs b/crates/udp/src/config.rs index 81580bf..ee2ef45 100644 --- a/crates/udp/src/config.rs +++ b/crates/udp/src/config.rs @@ -225,6 +225,10 @@ impl StatisticsConfig { } } } + /// Skip info-hash collection if not required by the configuration + pub fn collect_info_hash(&self) -> bool { + (self.interval != 0) & (self.write_json_to_file | self.write_bin_to_file) + } } impl Default for StatisticsConfig { diff --git a/crates/udp/src/swarm.rs b/crates/udp/src/swarm.rs index b255cbe..cd0a51d 100644 --- a/crates/udp/src/swarm.rs +++ b/crates/udp/src/swarm.rs @@ -389,7 +389,7 @@ impl TorrentMapShards { total_num_torrents += torrent_map_shard.len(); - if config.statistics.write_json_to_file { + if config.statistics.collect_info_hash() { info_hashes.reserve(total_num_torrents); for (k, _) in torrent_map_shard.iter() { info_hashes.push(*k)