From e2d12d184e28464903065fbea23991f936383212 Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:11:42 -0400 Subject: [PATCH] Use make_unique instead of using new (#4502) Signed-off-by: pasta --- src/chainparams.cpp | 8 ++++---- src/coinjoin/util.cpp | 2 +- src/httpserver.cpp | 4 ++-- src/init.cpp | 2 +- src/policy/fees.cpp | 12 ++++++------ src/support/lockedpool.cpp | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6a732667e5..44cba1dec7 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -1160,13 +1160,13 @@ const CChainParams &Params() { std::unique_ptr CreateChainParams(const std::string& chain) { if (chain == CBaseChainParams::MAIN) - return std::unique_ptr(new CMainParams()); + return std::make_unique(); else if (chain == CBaseChainParams::TESTNET) - return std::unique_ptr(new CTestNetParams()); + return std::make_unique(); else if (chain == CBaseChainParams::DEVNET) { - return std::unique_ptr(new CDevNetParams(gArgs)); + return std::make_unique(gArgs); } else if (chain == CBaseChainParams::REGTEST) - return std::unique_ptr(new CRegTestParams(gArgs)); + return std::make_unique(gArgs); throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain)); } diff --git a/src/coinjoin/util.cpp b/src/coinjoin/util.cpp index c589b1fdd4..4e4aafb420 100644 --- a/src/coinjoin/util.cpp +++ b/src/coinjoin/util.cpp @@ -42,7 +42,7 @@ CScript CKeyHolder::GetScriptForDestination() const CScript CKeyHolderStorage::AddKey(CWallet* pwallet) { - auto keyHolderPtr = std::unique_ptr(new CKeyHolder(pwallet)); + auto keyHolderPtr = std::make_unique(pwallet); auto script = keyHolderPtr->GetScriptForDestination(); LOCK(cs_storage); diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 149b876f1d..54a585327c 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -226,7 +226,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg) } } } - std::unique_ptr hreq(new HTTPRequest(req)); + auto hreq{std::make_unique(req)}; // Early address-based allow check if (!ClientAllowed(hreq->GetPeer())) { @@ -266,7 +266,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg) // Dispatch to worker thread if (i != iend) { - std::unique_ptr item(new HTTPWorkItem(std::move(hreq), path, i->handler)); + auto item{std::make_unique(std::move(hreq), path, i->handler)}; assert(g_work_queue); if (g_work_queue->Enqueue(item.get())) { item.release(); /* if true, queue took ownership */ diff --git a/src/init.cpp b/src/init.cpp index 1d6c08459e..2aecc54d2a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1782,7 +1782,7 @@ bool AppInitMain() assert(!g_banman); g_banman = MakeUnique(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME)); assert(!g_connman); - g_connman = std::unique_ptr(new CConnman(GetRand(std::numeric_limits::max()), GetRand(std::numeric_limits::max()))); + g_connman = std::make_unique(GetRand(std::numeric_limits::max()), GetRand(std::numeric_limits::max())); peerLogic.reset(new PeerLogicValidation(g_connman.get(), g_banman.get(), scheduler, gArgs.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61))); RegisterValidationInterface(peerLogic.get()); diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 6bf2dff409..b5dcc28432 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -537,9 +537,9 @@ CBlockPolicyEstimator::CBlockPolicyEstimator() bucketMap[INF_FEERATE] = bucketIndex; assert(bucketMap.size() == buckets.size()); - feeStats = std::unique_ptr(new TxConfirmStats(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE)); - shortStats = std::unique_ptr(new TxConfirmStats(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE)); - longStats = std::unique_ptr(new TxConfirmStats(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE)); + feeStats = std::make_unique(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE); + shortStats = std::make_unique(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE); + longStats = std::make_unique(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE); } CBlockPolicyEstimator::~CBlockPolicyEstimator() @@ -949,9 +949,9 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein) if (numBuckets <= 1 || numBuckets > 1000) throw std::runtime_error("Corrupt estimates file. Must have between 2 and 1000 feerate buckets"); - std::unique_ptr fileFeeStats(new TxConfirmStats(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE)); - std::unique_ptr fileShortStats(new TxConfirmStats(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE)); - std::unique_ptr fileLongStats(new TxConfirmStats(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE)); + auto fileFeeStats{std::make_unique(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE)}; + auto fileShortStats{std::make_unique(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE)}; + auto fileLongStats{std::make_unique(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE)}; fileFeeStats->Read(filein, nVersionThatWrote, numBuckets); fileShortStats->Read(filein, nVersionThatWrote, numBuckets); fileLongStats->Read(filein, nVersionThatWrote, numBuckets); diff --git a/src/support/lockedpool.cpp b/src/support/lockedpool.cpp index ba35b5a07c..b1fed6c9b2 100644 --- a/src/support/lockedpool.cpp +++ b/src/support/lockedpool.cpp @@ -408,9 +408,9 @@ void LockedPoolManager::CreateInstance() // have a static deinitialization order/problem, but the check in // LockedPoolManagerBase's destructor helps us detect if that ever happens. #ifdef WIN32 - std::unique_ptr allocator(new Win32LockedPageAllocator()); + std::unique_ptr allocator{std::make_unique()}; #else - std::unique_ptr allocator(new PosixLockedPageAllocator()); + std::unique_ptr allocator{std::make_unique()}; #endif static LockedPoolManager instance(std::move(allocator)); LockedPoolManager::_instance = &instance;