From f5634144c66544207941bca128c8c47d03960150 Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 26 Feb 2024 18:29:10 +0000 Subject: [PATCH] incompleteHosts is multiset, not list, so size() is constant-time --- scan_engine.cc | 21 ++------------------- scan_engine.h | 1 - 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/scan_engine.cc b/scan_engine.cc index 71623d7ad..a91b0d69b 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -390,7 +390,7 @@ bool GroupScanStats::sendOK(struct timeval *when) const { /* When there is only one target left, let the host congestion stuff deal with it. */ - if (USI->numIncompleteHostsLessThan(2)) { + if (USI->numIncompleteHosts() < 2) { if (when) *when = USI->now; return true; @@ -1114,28 +1114,11 @@ HostScanStats *UltraScanInfo::findHost(struct sockaddr_storage *ss) const { return NULL; } -/* Check if incompleteHosts list contains less than n elements. This function - is here to replace numIncompleteHosts() < n, which would have to walk - through the entire list. */ -bool UltraScanInfo::numIncompleteHostsLessThan(unsigned int n) const { - std::multiset::const_iterator hostI; - unsigned int count; - - count = 0; - hostI = incompleteHosts.begin(); - while (count < n && hostI != incompleteHosts.end()) { - hostI++; - count++; - } - - return count < n; -} - static bool pingprobe_is_better(const probespec *new_probe, int new_state, const probespec *old_probe, int old_state); /* Removes any hosts that have completed their scans from the incompleteHosts - list, and remove any hosts from completedHosts which have exceeded their + set, and remove any hosts from completedHosts which have exceeded their lifetime. Returns the number of hosts removed. */ int UltraScanInfo::removeCompletedHosts() { std::multiset::iterator hostI, nxt; diff --git a/scan_engine.h b/scan_engine.h index 3d49d15a3..51bcf8526 100644 --- a/scan_engine.h +++ b/scan_engine.h @@ -598,7 +598,6 @@ public: bool incompleteHostsEmpty() const { return incompleteHosts.empty(); } - bool numIncompleteHostsLessThan(unsigned int n) const; unsigned int numInitialHosts() const { return numInitialTargets;