Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost::clamp with std::clamp #3903

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ripple/app/misc/impl/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <ripple/json/json_reader.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/Sign.h>
#include <boost/algorithm/clamp.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <numeric>
#include <stdexcept>
Expand Down
9 changes: 4 additions & 5 deletions src/ripple/app/misc/impl/TxQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/jss.h>
#include <ripple/protocol/st.h>
#include <boost/algorithm/clamp.hpp>
#include <algorithm>
#include <limits>
#include <numeric>
Expand Down Expand Up @@ -111,11 +110,11 @@ TxQ::FeeMetrics::update(
// Ledgers are taking to long to process,
// so clamp down on limits.
auto const cutPct = 100 - setup.slowConsensusDecreasePercent;
// upperLimit must be >= minimumTxnCount_ or boost::clamp can give
// upperLimit must be >= minimumTxnCount_ or std::clamp can give
// unexpected results
auto const upperLimit = std::max<std::uint64_t>(
mulDiv(txnsExpected_, cutPct, 100).second, minimumTxnCount_);
txnsExpected_ = boost::algorithm::clamp(
txnsExpected_ = std::clamp<std::uint64_t>(
mulDiv(size, cutPct, 100).second, minimumTxnCount_, upperLimit);
recentTxnCounts_.clear();
}
Expand Down Expand Up @@ -1885,7 +1884,7 @@ setup_TxQ(Config const& config)
"normal_consensus_increase_percent",
section);
setup.normalConsensusIncreasePercent =
boost::algorithm::clamp(setup.normalConsensusIncreasePercent, 0, 1000);
std::clamp(setup.normalConsensusIncreasePercent, 0u, 1000u);

/* If this percentage is outside of the 0-100 range, the results
are nonsensical (uint overflows happen, so the limit grows
Expand All @@ -1895,7 +1894,7 @@ setup_TxQ(Config const& config)
"slow_consensus_decrease_percent",
section);
setup.slowConsensusDecreasePercent =
boost::algorithm::clamp(setup.slowConsensusDecreasePercent, 0, 100);
std::clamp(setup.slowConsensusDecreasePercent, 0u, 100u);

set(setup.maximumTxnPerAccount, "maximum_txn_per_account", section);
set(setup.minimumLastLedgerBuffer, "minimum_last_ledger_buffer", section);
Expand Down
5 changes: 2 additions & 3 deletions src/ripple/app/misc/impl/ValidatorSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <ripple/json/json_reader.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/jss.h>
#include <boost/algorithm/clamp.hpp>
#include <algorithm>

namespace ripple {
Expand Down Expand Up @@ -468,10 +467,10 @@ ValidatorSite::parseJsonResponse(
body[jss::refresh_interval].isNumeric())
{
using namespace std::chrono_literals;
std::chrono::minutes const refresh = boost::algorithm::clamp(
std::chrono::minutes const refresh = std::clamp(
std::chrono::minutes{body[jss::refresh_interval].asUInt()},
1min,
24h);
std::chrono::minutes{24h});
sites_[siteIdx].refreshInterval = refresh;
sites_[siteIdx].nextRefresh =
clock_type::now() + sites_[siteIdx].refreshInterval;
Expand Down
4 changes: 1 addition & 3 deletions src/ripple/app/paths/PathRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <ripple/protocol/UintTypes.h>

#include <ripple/rpc/impl/Tuning.h>
#include <boost/algorithm/clamp.hpp>
#include <optional>

#include <tuple>
Expand Down Expand Up @@ -624,8 +623,7 @@ PathRequest::findPaths(
after four source currencies, 50 - (4 * 4) = 34.
*/
int const size = sourceCurrencies.size();
consumer_.charge(
{boost::algorithm::clamp(size * size + 34, 50, 400), "path update"});
consumer_.charge({std::clamp(size * size + 34, 50, 400), "path update"});
return true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/ripple/nodestore/impl/ShardInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/digest.h>

#include <boost/algorithm/clamp.hpp>

namespace ripple {
namespace NodeStore {

Expand Down
3 changes: 1 addition & 2 deletions src/ripple/overlay/impl/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <ripple/overlay/predicates.h>
#include <ripple/protocol/digest.h>

#include <boost/algorithm/clamp.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/beast/core/ostream.hpp>
Expand Down Expand Up @@ -1825,7 +1824,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMProposeSet> const& m)

// Preliminary check for the validity of the signature: A DER encoded
// signature can't be longer than 72 bytes.
if ((boost::algorithm::clamp(sig.size(), 64, 72) != sig.size()) ||
if ((std::clamp<std::size_t>(sig.size(), 64, 72) != sig.size()) ||
(publicKeyType(makeSlice(set.nodepubkey())) != KeyType::secp256k1))
{
JLOG(p_journal_.warn()) << "Proposal: malformed";
Expand Down