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

Remove MakeUnique #1315

Merged
merged 2 commits into from
Jun 1, 2022
Merged
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/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ DEFI_CORE_H = \
util/error.h \
util/fees.h \
util/system.h \
util/memory.h \
util/moneystr.h \
util/rbf.h \
util/string.h \
Expand Down
4 changes: 2 additions & 2 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<st
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
tx.vout.resize(1);
tx.vout[0].nValue = nValue;
wtxs.push_back(MakeUnique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))));
wtxs.push_back(std::make_unique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))));
}

// Simple benchmark for wallet coin selection. Note that it maybe be necessary
Expand Down Expand Up @@ -70,7 +70,7 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector<OutputGroup>
CMutableTransaction tx;
tx.vout.resize(nInput + 1);
tx.vout[nInput].nValue = nValue;
std::unique_ptr<CWalletTx> wtx = MakeUnique<CWalletTx>(&testWallet, MakeTransactionRef(std::move(tx)));
std::unique_ptr<CWalletTx> wtx = std::make_unique<CWalletTx>(&testWallet, MakeTransactionRef(std::move(tx)));
set.emplace_back(COutput(wtx.get(), nInput, 0, true, true, true).GetInputCoin(), 0, true, 0, 0);
wtxn.emplace_back(std::move(wtx));
}
Expand Down
9 changes: 4 additions & 5 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <tinyformat.h>
#include <util/system.h>
#include <util/memory.h>

#include <assert.h>

Expand Down Expand Up @@ -37,13 +36,13 @@ const CBaseChainParams& BaseParams()
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN)
return MakeUnique<CBaseChainParams>("", 8554);
return std::make_unique<CBaseChainParams>("", 8554);
else if (chain == CBaseChainParams::TESTNET)
return MakeUnique<CBaseChainParams>("testnet3", 18554);
return std::make_unique<CBaseChainParams>("testnet3", 18554);
else if (chain == CBaseChainParams::DEVNET)
return MakeUnique<CBaseChainParams>("devnet", 20554);
return std::make_unique<CBaseChainParams>("devnet", 20554);
else if (chain == CBaseChainParams::REGTEST)
return MakeUnique<CBaseChainParams>("regtest", 19554);
return std::make_unique<CBaseChainParams>("regtest", 19554);
else
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
Expand Down
8 changes: 4 additions & 4 deletions src/flushablestorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class CStorageLevelDB : public CStorageKV {
return batch.SizeEstimate();
}
std::unique_ptr<CStorageKVIterator> NewIterator() override {
return MakeUnique<CStorageLevelDBIterator>(std::unique_ptr<CDBIterator>(db.NewIterator()));
return std::make_unique<CStorageLevelDBIterator>(std::unique_ptr<CDBIterator>(db.NewIterator()));
}
void Compact(const TBytes& begin, const TBytes& end) {
db.CompactRange(refTBytes(begin), refTBytes(end));
Expand Down Expand Up @@ -317,7 +317,7 @@ class CFlushableStorageKV : public CStorageKV {
return memusage::DynamicUsage(changed);
}
std::unique_ptr<CStorageKVIterator> NewIterator() override {
return MakeUnique<CFlushableStorageKVIterator>(db.NewIterator(), changed);
return std::make_unique<CFlushableStorageKVIterator>(db.NewIterator(), changed);
}

MapKV& GetRaw() {
Expand Down Expand Up @@ -427,8 +427,8 @@ class CStorageIteratorWrapper {
// Creates an iterator to single level key value storage
template<typename By, typename KeyType>
CStorageIteratorWrapper<By, KeyType> NewKVIterator(const KeyType& key, MapKV& map) {
auto emptyParent = MakeUnique<CStorageKVEmptyIterator>();
auto flushableIterator = MakeUnique<CFlushableStorageKVIterator>(std::move(emptyParent), map);
auto emptyParent = std::make_unique<CStorageKVEmptyIterator>();
auto flushableIterator = std::make_unique<CFlushableStorageKVIterator>(std::move(emptyParent), map);
CStorageIteratorWrapper<By, KeyType> it{std::move(flushableIterator)};
it.Seek(key);
return it;
Expand Down
2 changes: 1 addition & 1 deletion src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ bool StartHTTPRPC()
}
struct event_base* eventBase = EventBase();
assert(eventBase);
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(eventBase);
httpRPCTimerInterface = std::make_unique<HTTPRPCTimerInterface>(eventBase);
RPCSetTimerInterface(httpRPCTimerInterface.get());
if (statsRPC.isActive()) statsRPC.load();
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/index/blockfilterindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type,
fs::create_directories(path);

m_name = filter_name + " block filter index";
m_db = MakeUnique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
m_filter_fileseq = MakeUnique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
}

bool BlockFilterIndex::Init()
Expand Down
2 changes: 1 addition & 1 deletion src/index/txindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool TxIndex::DB::MigrateData(CBlockTreeDB& block_tree_db, const CBlockLocator&
}

TxIndex::TxIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
: m_db(MakeUnique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
: m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
{}

TxIndex::~TxIndex() {}
Expand Down
28 changes: 14 additions & 14 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ bool AppInitLockDataDirectory()
void SetupAnchorSPVDatabases(bool resync) {
// Close and open database
panchors.reset();
panchors = MakeUnique<CAnchorIndex>(nDefaultDbCache << 20, false, gArgs.GetBoolArg("-spv", true) && resync);
panchors = std::make_unique<CAnchorIndex>(nDefaultDbCache << 20, false, gArgs.GetBoolArg("-spv", true) && resync);

// load anchors after spv due to spv (and spv height) not set before (no last height yet)
if (gArgs.GetBoolArg("-spv", true)) {
Expand All @@ -1288,11 +1288,11 @@ void SetupAnchorSPVDatabases(bool resync) {

// Open database based on network
if (Params().NetworkIDString() == "regtest") {
spv::pspv = MakeUnique<spv::CFakeSpvWrapper>();
spv::pspv = std::make_unique<spv::CFakeSpvWrapper>();
} else if (Params().NetworkIDString() == "test" || Params().NetworkIDString() == "devnet") {
spv::pspv = MakeUnique<spv::CSpvWrapper>(false, nMinDbCache << 20, false, resync);
spv::pspv = std::make_unique<spv::CSpvWrapper>(false, nMinDbCache << 20, false, resync);
} else {
spv::pspv = MakeUnique<spv::CSpvWrapper>(true, nMinDbCache << 20, false, resync);
spv::pspv = std::make_unique<spv::CSpvWrapper>(true, nMinDbCache << 20, false, resync);
}
}
}
Expand Down Expand Up @@ -1433,7 +1433,7 @@ bool AppInitMain(InitInterfaces& interfaces)
// need to reindex later.

assert(!g_banman);
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
g_banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
assert(!g_connman);
g_connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));

Expand Down Expand Up @@ -1595,7 +1595,7 @@ bool AppInitMain(InitInterfaces& interfaces)
try {
LOCK(cs_main);
// This statement makes ::ChainstateActive() usable.
g_chainstate = MakeUnique<CChainState>();
g_chainstate = std::make_unique<CChainState>();
UnloadBlockIndex();

// new CBlockTreeDB tries to delete the existing file, which
Expand Down Expand Up @@ -1660,9 +1660,9 @@ bool AppInitMain(InitInterfaces& interfaces)
});

pcustomcsDB.reset();
pcustomcsDB = MakeUnique<CStorageLevelDB>(GetDataDir() / "enhancedcs", nCustomCacheSize, false, fReset || fReindexChainState);
pcustomcsDB = std::make_unique<CStorageLevelDB>(GetDataDir() / "enhancedcs", nCustomCacheSize, false, fReset || fReindexChainState);
pcustomcsview.reset();
pcustomcsview = MakeUnique<CCustomCSView>(*pcustomcsDB.get());
pcustomcsview = std::make_unique<CCustomCSView>(*pcustomcsDB.get());
if (!fReset && !fReindexChainState) {
if (!pcustomcsDB->IsEmpty() && pcustomcsview->GetDbVersion() != CCustomCSView::DbVersion) {
strLoadError = _("Account database is unsuitable").translated;
Expand All @@ -1676,16 +1676,16 @@ bool AppInitMain(InitInterfaces& interfaces)
// make account history db
paccountHistoryDB.reset();
if (gArgs.GetBoolArg("-acindex", DEFAULT_ACINDEX)) {
paccountHistoryDB = MakeUnique<CAccountHistoryStorage>(GetDataDir() / "history", nCustomCacheSize, false, fReset || fReindexChainState);
paccountHistoryDB = std::make_unique<CAccountHistoryStorage>(GetDataDir() / "history", nCustomCacheSize, false, fReset || fReindexChainState);
}

pburnHistoryDB.reset();
pburnHistoryDB = MakeUnique<CBurnHistoryStorage>(GetDataDir() / "burn", nCustomCacheSize, false, fReset || fReindexChainState);
pburnHistoryDB = std::make_unique<CBurnHistoryStorage>(GetDataDir() / "burn", nCustomCacheSize, false, fReset || fReindexChainState);

// Create vault history DB
pvaultHistoryDB.reset();
if (gArgs.GetBoolArg("-vaultindex", DEFAULT_VAULTINDEX)) {
pvaultHistoryDB = MakeUnique<CVaultHistoryStorage>(GetDataDir() / "vault", nCustomCacheSize, false, fReset || fReindexChainState);
pvaultHistoryDB = std::make_unique<CVaultHistoryStorage>(GetDataDir() / "vault", nCustomCacheSize, false, fReset || fReindexChainState);
}

// If necessary, upgrade from older database format.
Expand Down Expand Up @@ -1803,7 +1803,7 @@ bool AppInitMain(InitInterfaces& interfaces)

// ********************************************************* Step 8: start indexers
if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
g_txindex = MakeUnique<TxIndex>(nTxIndexCache, false, fReindex);
g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false, fReindex);
g_txindex->Start();
}

Expand All @@ -1825,9 +1825,9 @@ bool AppInitMain(InitInterfaces& interfaces)
LOCK(cs_main);

panchorauths.reset();
panchorauths = MakeUnique<CAnchorAuthIndex>();
panchorauths = std::make_unique<CAnchorAuthIndex>();
panchorAwaitingConfirms.reset();
panchorAwaitingConfirms = MakeUnique<CAnchorAwaitingConfirms>();
panchorAwaitingConfirms = std::make_unique<CAnchorAwaitingConfirms>();
SetupAnchorSPVDatabases(gArgs.GetBoolArg("-spv_resync", fReindex || fReindexChainState));

// Check if DB version changed
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ChainImpl : public Chain
public:
std::unique_ptr<Chain::Lock> lock() override
{
return MakeUnique<LockImpl>(::cs_main);
return std::make_unique<LockImpl>(::cs_main);
}
bool findBlock(const uint256& hash, CBlock* block, int64_t* time, int64_t* time_max) override
{
Expand Down Expand Up @@ -365,7 +365,7 @@ class ChainImpl : public Chain
}
std::unique_ptr<Handler> handleNotifications(Notifications& notifications) override
{
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
return std::make_unique<NotificationsHandlerImpl>(*this, notifications);
}
void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) override
{
Expand All @@ -379,7 +379,7 @@ class ChainImpl : public Chain
}
std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) override
{
return MakeUnique<RpcHandlerImpl>(command);
return std::make_unique<RpcHandlerImpl>(command);
}
bool rpcEnableDeprecated(const std::string& method) override { return IsDeprecatedRPCEnabled(method); }
void rpcRunLater(const std::string& name, std::function<void()> fn, int64_t seconds) override
Expand All @@ -397,6 +397,6 @@ class ChainImpl : public Chain
};
} // namespace

std::unique_ptr<Chain> MakeChain() { return MakeUnique<ChainImpl>(); }
std::unique_ptr<Chain> MakeChain() { return std::make_unique<ChainImpl>(); }

} // namespace interfaces
3 changes: 1 addition & 2 deletions src/interfaces/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <interfaces/handler.h>

#include <util/memory.h>

#include <boost/signals2/connection.hpp>
#include <utility>
Expand All @@ -26,7 +25,7 @@ class HandlerImpl : public Handler

std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
{
return MakeUnique<HandlerImpl>(std::move(connection));
return std::make_unique<HandlerImpl>(std::move(connection));
}

} // namespace interfaces
14 changes: 7 additions & 7 deletions src/masternodes/icxorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::unique_ptr<CICXOrderView::CICXOrderImpl> CICXOrderView::GetICXOrderByCreati
{
auto order = ReadBy<ICXOrderCreationTx,CICXOrderImpl>(txid);
if (order)
return MakeUnique<CICXOrderImpl>(*order);
return std::make_unique<CICXOrderImpl>(*order);
return {};
}

Expand Down Expand Up @@ -138,7 +138,7 @@ std::unique_ptr<CICXOrderView::CICXMakeOfferImpl> CICXOrderView::GetICXMakeOffer
{
auto makeoffer = ReadBy<ICXMakeOfferCreationTx,CICXMakeOfferImpl>(txid);
if (makeoffer)
return MakeUnique<CICXMakeOfferImpl>(*makeoffer);
return std::make_unique<CICXMakeOfferImpl>(*makeoffer);
return {};
}

Expand Down Expand Up @@ -214,7 +214,7 @@ std::unique_ptr<CICXOrderView::CICXSubmitDFCHTLCImpl> CICXOrderView::GetICXSubmi
{
auto submitdfchtlc = ReadBy<ICXSubmitDFCHTLCCreationTx,CICXSubmitDFCHTLCImpl>(txid);
if (submitdfchtlc)
return MakeUnique<CICXSubmitDFCHTLCImpl>(*submitdfchtlc);
return std::make_unique<CICXSubmitDFCHTLCImpl>(*submitdfchtlc);
return {};
}

Expand Down Expand Up @@ -292,7 +292,7 @@ std::unique_ptr<CICXOrderView::CICXSubmitEXTHTLCImpl> CICXOrderView::GetICXSubmi
{
auto submitexthtlc = ReadBy<ICXSubmitEXTHTLCCreationTx,CICXSubmitEXTHTLCImpl>(txid);
if (submitexthtlc)
return MakeUnique<CICXSubmitEXTHTLCImpl>(*submitexthtlc);
return std::make_unique<CICXSubmitEXTHTLCImpl>(*submitexthtlc);
return {};
}

Expand Down Expand Up @@ -370,7 +370,7 @@ std::unique_ptr<CICXOrderView::CICXClaimDFCHTLCImpl> CICXOrderView::GetICXClaimD
{
auto claimdfchtlc = ReadBy<ICXClaimDFCHTLCCreationTx,CICXClaimDFCHTLCImpl>(txid);
if (claimdfchtlc)
return MakeUnique<CICXClaimDFCHTLCImpl>(*claimdfchtlc);
return std::make_unique<CICXClaimDFCHTLCImpl>(*claimdfchtlc);
return {};
}

Expand Down Expand Up @@ -398,7 +398,7 @@ std::unique_ptr<CICXOrderView::CICXCloseOrderImpl> CICXOrderView::GetICXCloseOrd
{
auto closeorderImpl = ReadBy<ICXCloseOrderCreationTx, CICXCloseOrderImpl>(txid);
if (closeorderImpl)
return MakeUnique<CICXCloseOrderImpl>(*closeorderImpl);
return std::make_unique<CICXCloseOrderImpl>(*closeorderImpl);
return {};
}

Expand All @@ -417,7 +417,7 @@ std::unique_ptr<CICXOrderView::CICXCloseOfferImpl> CICXOrderView::GetICXCloseOff
{
auto closeofferImpl = ReadBy<ICXCloseOfferCreationTx, CICXCloseOfferImpl>(txid);
if (closeofferImpl)
return MakeUnique<CICXCloseOfferImpl>(*closeofferImpl);
return std::make_unique<CICXCloseOfferImpl>(*closeofferImpl);
return {};
}

Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ UniValue listaccounthistory(const JSONRPCRequest& request) {

std::unique_ptr<CScopeAccountReverter> reverter;
if (!noRewards) {
reverter = MakeUnique<CScopeAccountReverter>(view, key.owner, valueLazy.get().diff);
reverter = std::make_unique<CScopeAccountReverter>(view, key.owner, valueLazy.get().diff);
}

bool accountRecord = true;
Expand Down Expand Up @@ -1526,7 +1526,7 @@ UniValue accounthistorycount(const JSONRPCRequest& request) {

std::unique_ptr<CScopeAccountReverter> reverter;
if (!noRewards) {
reverter = MakeUnique<CScopeAccountReverter>(view, key.owner, value.diff);
reverter = std::make_unique<CScopeAccountReverter>(view, key.owner, value.diff);
}

if (CustomTxType::None != txType && value.category != uint8_t(txType)) {
Expand Down
6 changes: 3 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,11 +2232,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)

if (semOutbound == nullptr) {
// initialize semaphore
semOutbound = MakeUnique<CSemaphore>(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
semOutbound = std::make_unique<CSemaphore>(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
}
if (semAddnode == nullptr) {
// initialize semaphore
semAddnode = MakeUnique<CSemaphore>(nMaxAddnode);
semAddnode = std::make_unique<CSemaphore>(nMaxAddnode);
}

//
Expand Down Expand Up @@ -2637,7 +2637,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
hashContinue = uint256();
filterInventoryKnown.reset();
pfilter = MakeUnique<CBloomFilter>();
pfilter = std::make_unique<CBloomFilter>();

for (const std::string &msg : getAllNetMessageTypes())
mapRecvBytesPerMsgCmd[msg] = 0;
Expand Down
Loading