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

@@ -99,7 +99,7 @@ void
ValidatorList::PublisherListStats::mergeDispositions(
PublisherListStats const& src)
{
for (auto const [disp, count] : src.dispositions)
for (auto const& [disp, count] : src.dispositions)
{
dispositions[disp] += count;
}

View File

@@ -408,7 +408,7 @@ ValidatorSite::parseJsonResponse(
sites_[siteIdx].lastRefreshStatus.emplace(
Site::Status{clock_type::now(), applyResult.bestDisposition(), ""});
for (auto const [disp, count] : applyResult.dispositions)
for (auto const& [disp, count] : applyResult.dispositions)
{
switch (disp)
{

View File

@@ -293,7 +293,7 @@ ConnectAttempt::processResponse()
Json::Reader r;
std::string s;
s.reserve(boost::asio::buffer_size(response_.body().data()));
for (auto const& buffer : response_.body().data())
for (auto const buffer : response_.body().data())
s.append(
boost::asio::buffer_cast<char const*>(buffer),
boost::asio::buffer_size(buffer));

View File

@@ -2168,7 +2168,7 @@ PeerImp::onValidatorListMessage(
}
// Log based on all the results.
for (auto const [disp, count] : applyResult.dispositions)
for (auto const& [disp, count] : applyResult.dispositions)
{
switch (disp)
{

View File

@@ -264,7 +264,9 @@ buffers_to_string(ConstBufferSequence const& bs)
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for (auto const& b : bs)
// Use auto&& so the right thing happens whether bs returns a copy or
// a reference
for (auto&& b : bs)
s.append(buffer_cast<char const*>(b), buffer_size(b));
return s;
}

View File

@@ -66,7 +66,7 @@ public:
auto const& buf = sb_.data();
std::vector<boost::asio::const_buffer> result;
result.reserve(std::distance(buf.begin(), buf.end()));
for (auto const& b : buf)
for (auto const b : buf)
result.push_back(b);
return result;
}

View File

@@ -865,7 +865,7 @@ class Check_test : public beast::unit_test::suite
// featureMultiSignReserve changes the reserve on a SignerList, so
// check both before and after.
FeatureBitset const allSupported{supported_amendments()};
for (auto const features :
for (auto const& features :
{allSupported - featureMultiSignReserve,
allSupported | featureMultiSignReserve})
{
@@ -1514,7 +1514,7 @@ class Check_test : public beast::unit_test::suite
// featureMultiSignReserve changes the reserve on a SignerList, so
// check both before and after.
FeatureBitset const allSupported{supported_amendments()};
for (auto const features :
for (auto const& features :
{allSupported - featureMultiSignReserve,
allSupported | featureMultiSignReserve})
{

View File

@@ -882,7 +882,7 @@ public:
//
// fix1578 changes the return code. Verify expected behavior
// without and with fix1578.
for (auto const tweakedFeatures :
for (auto const& tweakedFeatures :
{features - fix1578, features | fix1578})
{
Env env{*this, tweakedFeatures};

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)));

View File

@@ -75,7 +75,7 @@ class Invariants_test : public beast::unit_test::suite
return;
TER terActual = tesSUCCESS;
for (TER const terExpect : ters)
for (TER const& terExpect : ters)
{
terActual = ac.checkInvariants(terActual, fee);
BEAST_EXPECT(terExpect == terActual);

View File

@@ -84,7 +84,7 @@ public:
// fix1578 changes the return code. Verify expected behavior
// without and with fix1578.
for (auto const tweakedFeatures :
for (auto const& tweakedFeatures :
{features - fix1578, features | fix1578})
{
Env env(*this, tweakedFeatures);