mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 04:55:52 +00:00
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:
committed by
manojsdoshi
parent
22cc9a254a
commit
2a7c573dec
@@ -99,7 +99,7 @@ void
|
|||||||
ValidatorList::PublisherListStats::mergeDispositions(
|
ValidatorList::PublisherListStats::mergeDispositions(
|
||||||
PublisherListStats const& src)
|
PublisherListStats const& src)
|
||||||
{
|
{
|
||||||
for (auto const [disp, count] : src.dispositions)
|
for (auto const& [disp, count] : src.dispositions)
|
||||||
{
|
{
|
||||||
dispositions[disp] += count;
|
dispositions[disp] += count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -408,7 +408,7 @@ ValidatorSite::parseJsonResponse(
|
|||||||
sites_[siteIdx].lastRefreshStatus.emplace(
|
sites_[siteIdx].lastRefreshStatus.emplace(
|
||||||
Site::Status{clock_type::now(), applyResult.bestDisposition(), ""});
|
Site::Status{clock_type::now(), applyResult.bestDisposition(), ""});
|
||||||
|
|
||||||
for (auto const [disp, count] : applyResult.dispositions)
|
for (auto const& [disp, count] : applyResult.dispositions)
|
||||||
{
|
{
|
||||||
switch (disp)
|
switch (disp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ ConnectAttempt::processResponse()
|
|||||||
Json::Reader r;
|
Json::Reader r;
|
||||||
std::string s;
|
std::string s;
|
||||||
s.reserve(boost::asio::buffer_size(response_.body().data()));
|
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(
|
s.append(
|
||||||
boost::asio::buffer_cast<char const*>(buffer),
|
boost::asio::buffer_cast<char const*>(buffer),
|
||||||
boost::asio::buffer_size(buffer));
|
boost::asio::buffer_size(buffer));
|
||||||
|
|||||||
@@ -2168,7 +2168,7 @@ PeerImp::onValidatorListMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log based on all the results.
|
// Log based on all the results.
|
||||||
for (auto const [disp, count] : applyResult.dispositions)
|
for (auto const& [disp, count] : applyResult.dispositions)
|
||||||
{
|
{
|
||||||
switch (disp)
|
switch (disp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -264,7 +264,9 @@ buffers_to_string(ConstBufferSequence const& bs)
|
|||||||
using boost::asio::buffer_size;
|
using boost::asio::buffer_size;
|
||||||
std::string s;
|
std::string s;
|
||||||
s.reserve(buffer_size(bs));
|
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));
|
s.append(buffer_cast<char const*>(b), buffer_size(b));
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
auto const& buf = sb_.data();
|
auto const& buf = sb_.data();
|
||||||
std::vector<boost::asio::const_buffer> result;
|
std::vector<boost::asio::const_buffer> result;
|
||||||
result.reserve(std::distance(buf.begin(), buf.end()));
|
result.reserve(std::distance(buf.begin(), buf.end()));
|
||||||
for (auto const& b : buf)
|
for (auto const b : buf)
|
||||||
result.push_back(b);
|
result.push_back(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -865,7 +865,7 @@ class Check_test : public beast::unit_test::suite
|
|||||||
// featureMultiSignReserve changes the reserve on a SignerList, so
|
// featureMultiSignReserve changes the reserve on a SignerList, so
|
||||||
// check both before and after.
|
// check both before and after.
|
||||||
FeatureBitset const allSupported{supported_amendments()};
|
FeatureBitset const allSupported{supported_amendments()};
|
||||||
for (auto const features :
|
for (auto const& features :
|
||||||
{allSupported - featureMultiSignReserve,
|
{allSupported - featureMultiSignReserve,
|
||||||
allSupported | featureMultiSignReserve})
|
allSupported | featureMultiSignReserve})
|
||||||
{
|
{
|
||||||
@@ -1514,7 +1514,7 @@ class Check_test : public beast::unit_test::suite
|
|||||||
// featureMultiSignReserve changes the reserve on a SignerList, so
|
// featureMultiSignReserve changes the reserve on a SignerList, so
|
||||||
// check both before and after.
|
// check both before and after.
|
||||||
FeatureBitset const allSupported{supported_amendments()};
|
FeatureBitset const allSupported{supported_amendments()};
|
||||||
for (auto const features :
|
for (auto const& features :
|
||||||
{allSupported - featureMultiSignReserve,
|
{allSupported - featureMultiSignReserve,
|
||||||
allSupported | featureMultiSignReserve})
|
allSupported | featureMultiSignReserve})
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -882,7 +882,7 @@ public:
|
|||||||
//
|
//
|
||||||
// fix1578 changes the return code. Verify expected behavior
|
// fix1578 changes the return code. Verify expected behavior
|
||||||
// without and with fix1578.
|
// without and with fix1578.
|
||||||
for (auto const tweakedFeatures :
|
for (auto const& tweakedFeatures :
|
||||||
{features - fix1578, features | fix1578})
|
{features - fix1578, features | fix1578})
|
||||||
{
|
{
|
||||||
Env env{*this, tweakedFeatures};
|
Env env{*this, tweakedFeatures};
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
auto t = scheduler.in(1s, [&] { set.insert(0); });
|
auto t = scheduler.in(1s, [&] { set.insert(0); });
|
||||||
if (id == 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] {
|
net.send(this, link.target, [&, to = link.target] {
|
||||||
to->receive(net, this, 1);
|
to->receive(net, this, 1);
|
||||||
});
|
});
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
++m;
|
++m;
|
||||||
if (m < 5)
|
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] {
|
net.send(this, link.target, [&, mm = m, to = link.target] {
|
||||||
to->receive(net, this, mm);
|
to->receive(net, this, mm);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ struct Peer
|
|||||||
bool
|
bool
|
||||||
trusts(PeerID const& oId)
|
trusts(PeerID const& oId)
|
||||||
{
|
{
|
||||||
for (auto const& p : trustGraph.trustedPeers(this))
|
for (auto const p : trustGraph.trustedPeers(this))
|
||||||
if (p->id == oId)
|
if (p->id == oId)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@@ -404,7 +404,7 @@ struct Peer
|
|||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
SimDuration minDuration{10s};
|
SimDuration minDuration{10s};
|
||||||
for (auto const& link : net.links(this))
|
for (auto const link : net.links(this))
|
||||||
{
|
{
|
||||||
minDuration = std::min(minDuration, link.data.delay);
|
minDuration = std::min(minDuration, link.data.delay);
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ struct Peer
|
|||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
SimDuration minDuration{10s};
|
SimDuration minDuration{10s};
|
||||||
for (auto const& link : net.links(this))
|
for (auto const link : net.links(this))
|
||||||
{
|
{
|
||||||
minDuration = std::min(minDuration, link.data.delay);
|
minDuration = std::min(minDuration, link.data.delay);
|
||||||
// Send a message to neighbors to find the tx set
|
// Send a message to neighbors to find the tx set
|
||||||
@@ -741,7 +741,7 @@ struct Peer
|
|||||||
void
|
void
|
||||||
send(BroadcastMesg<M> const& bm, PeerID from)
|
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)
|
if (link.target->id != from && link.target->id != bm.origin)
|
||||||
{
|
{
|
||||||
@@ -848,7 +848,7 @@ struct Peer
|
|||||||
getQuorumKeys()
|
getQuorumKeys()
|
||||||
{
|
{
|
||||||
hash_set<NodeKey_t> keys;
|
hash_set<NodeKey_t> keys;
|
||||||
for (auto const& p : trustGraph.trustedPeers(this))
|
for (auto const p : trustGraph.trustedPeers(this))
|
||||||
keys.insert(p->key);
|
keys.insert(p->key);
|
||||||
return {quorum, keys};
|
return {quorum, keys};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public:
|
|||||||
|
|
||||||
using UNL = std::set<Peer>;
|
using UNL = std::set<Peer>;
|
||||||
std::set<UNL> unique;
|
std::set<UNL> unique;
|
||||||
for (Peer const& peer : graph_.outVertices())
|
for (Peer const peer : graph_.outVertices())
|
||||||
{
|
{
|
||||||
unique.emplace(
|
unique.emplace(
|
||||||
std::begin(trustedPeers(peer)), std::end(trustedPeers(peer)));
|
std::begin(trustedPeers(peer)), std::end(trustedPeers(peer)));
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class Invariants_test : public beast::unit_test::suite
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
TER terActual = tesSUCCESS;
|
TER terActual = tesSUCCESS;
|
||||||
for (TER const terExpect : ters)
|
for (TER const& terExpect : ters)
|
||||||
{
|
{
|
||||||
terActual = ac.checkInvariants(terActual, fee);
|
terActual = ac.checkInvariants(terActual, fee);
|
||||||
BEAST_EXPECT(terExpect == terActual);
|
BEAST_EXPECT(terExpect == terActual);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
|
|
||||||
// fix1578 changes the return code. Verify expected behavior
|
// fix1578 changes the return code. Verify expected behavior
|
||||||
// without and with fix1578.
|
// without and with fix1578.
|
||||||
for (auto const tweakedFeatures :
|
for (auto const& tweakedFeatures :
|
||||||
{features - fix1578, features | fix1578})
|
{features - fix1578, features | fix1578})
|
||||||
{
|
{
|
||||||
Env env(*this, tweakedFeatures);
|
Env env(*this, tweakedFeatures);
|
||||||
|
|||||||
Reference in New Issue
Block a user