random: drop ad-hoc Shuffle in favor of std::shuffle

Benchmarks show it is no longer faster with modern standard C++ libraries,
and the debug-mode failure due to self-move has been fixed as well.
This commit is contained in:
Pieter Wuille
2024-07-05 10:45:54 -04:00
parent da28a26aae
commit 6ecda04fef
14 changed files with 19 additions and 61 deletions

View File

@@ -415,7 +415,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
if (pszDest) {
std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
if (!resolved.empty()) {
Shuffle(resolved.begin(), resolved.end(), FastRandomContext());
std::shuffle(resolved.begin(), resolved.end(), FastRandomContext());
// If the connection is made by name, it can be the case that the name resolves to more than one address.
// We don't want to connect any more of them if we are already connected to one
for (const auto& r : resolved) {
@@ -2208,7 +2208,7 @@ void CConnman::ThreadDNSAddressSeed()
FastRandomContext rng;
std::vector<std::string> seeds = m_params.DNSSeeds();
Shuffle(seeds.begin(), seeds.end(), rng);
std::shuffle(seeds.begin(), seeds.end(), rng);
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
if (gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED)) {
@@ -2435,7 +2435,7 @@ bool CConnman::MultipleManualOrFullOutboundConns(Network net) const
bool CConnman::MaybePickPreferredNetwork(std::optional<Network>& network)
{
std::array<Network, 5> nets{NET_IPV4, NET_IPV6, NET_ONION, NET_I2P, NET_CJDNS};
Shuffle(nets.begin(), nets.end(), FastRandomContext());
std::shuffle(nets.begin(), nets.end(), FastRandomContext());
LOCK(m_nodes_mutex);
for (const auto net : nets) {