Fix clang warnings about copies vs references:

A recent version of clang notes a number of places in range
for loops where the code base was making unnecessary copies
or using const lvalue references to extend lifetimes.  This
fixes the places that clang identified.
This commit is contained in:
Scott Schurr
2021-05-20 15:45:56 -07:00
committed by manojsdoshi
parent 22cc9a254a
commit 2a7c573dec
13 changed files with 21 additions and 19 deletions

View File

@@ -49,7 +49,7 @@ public:
auto t = scheduler.in(1s, [&] { set.insert(0); });
if (id == 0)
{
for (auto const& link : net.links(this))
for (auto const link : net.links(this))
net.send(this, link.target, [&, to = link.target] {
to->receive(net, this, 1);
});
@@ -68,7 +68,7 @@ public:
++m;
if (m < 5)
{
for (auto const& link : net.links(this))
for (auto const link : net.links(this))
net.send(this, link.target, [&, mm = m, to = link.target] {
to->receive(net, this, mm);
});

View File

@@ -344,7 +344,7 @@ struct Peer
bool
trusts(PeerID const& oId)
{
for (auto const& p : trustGraph.trustedPeers(this))
for (auto const p : trustGraph.trustedPeers(this))
if (p->id == oId)
return true;
return false;
@@ -404,7 +404,7 @@ struct Peer
using namespace std::chrono_literals;
SimDuration minDuration{10s};
for (auto const& link : net.links(this))
for (auto const link : net.links(this))
{
minDuration = std::min(minDuration, link.data.delay);
@@ -451,7 +451,7 @@ struct Peer
using namespace std::chrono_literals;
SimDuration minDuration{10s};
for (auto const& link : net.links(this))
for (auto const link : net.links(this))
{
minDuration = std::min(minDuration, link.data.delay);
// Send a message to neighbors to find the tx set
@@ -741,7 +741,7 @@ struct Peer
void
send(BroadcastMesg<M> const& bm, PeerID from)
{
for (auto const& link : net.links(this))
for (auto const link : net.links(this))
{
if (link.target->id != from && link.target->id != bm.origin)
{
@@ -848,7 +848,7 @@ struct Peer
getQuorumKeys()
{
hash_set<NodeKey_t> keys;
for (auto const& p : trustGraph.trustedPeers(this))
for (auto const p : trustGraph.trustedPeers(this))
keys.insert(p->key);
return {quorum, keys};
}

View File

@@ -126,7 +126,7 @@ public:
using UNL = std::set<Peer>;
std::set<UNL> unique;
for (Peer const& peer : graph_.outVertices())
for (Peer const peer : graph_.outVertices())
{
unique.emplace(
std::begin(trustedPeers(peer)), std::end(trustedPeers(peer)));