Replace boost::clamp with std::clamp

This commit is contained in:
Howard Hinnant
2021-08-11 15:19:12 -04:00
committed by Nik Bougalis
parent cf70ecbd6d
commit 9f75f2d522
6 changed files with 8 additions and 16 deletions

View File

@@ -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>

View File

@@ -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>
@@ -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();
}
@@ -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
@@ -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);

View File

@@ -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 {
@@ -469,10 +468,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;

View File

@@ -33,7 +33,6 @@
#include <ripple/protocol/UintTypes.h>
#include <ripple/rpc/impl/Tuning.h>
#include <boost/algorithm/clamp.hpp>
#include <optional>
#include <tuple>
@@ -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;
}

View File

@@ -23,8 +23,6 @@
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/digest.h>
#include <boost/algorithm/clamp.hpp>
namespace ripple {
namespace NodeStore {

View File

@@ -41,7 +41,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>
@@ -1910,7 +1909,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";