Skip to content

Commit

Permalink
Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...))
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and fdoving committed Dec 19, 2021
1 parent bb01923 commit a4e806f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool StartHTTPRPC()
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
#endif
assert(EventBase());
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase()));
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
RPCSetTimerInterface(httpRPCTimerInterface.get());
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2363,11 +2363,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)

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

//
Expand Down Expand Up @@ -2785,7 +2785,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nNextInvSend = 0;
fRelayTxes = false;
fSentAddr = false;
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter());
pfilter = MakeUnique<CBloomFilter>();
timeLastMempoolReq = 0;
nLastBlockTime = 0;
nLastTXTime = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
}
LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());

std::unique_ptr<Db> pdbCopy(new Db(bitdb.dbenv.get(), 0));
std::unique_ptr<Db> pdbCopy = MakeUnique<Db>(bitdb.dbenv.get(), 0);
int ret = pdbCopy->open(nullptr, // Txn pointer
filename.c_str(), // Filename
"main", // Logical db name
Expand Down Expand Up @@ -523,7 +523,7 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
std::string strFileRes = strFile + ".rewrite";
{ // surround usage of db with extra {}
CDB db(dbw, "r");
std::unique_ptr<Db> pdbCopy = std::unique_ptr<Db>(new Db(env->dbenv.get(), 0));
std::unique_ptr<Db> pdbCopy = MakeUnique<Db>(env->dbenv.get(), 0);

int ret = pdbCopy->open(nullptr, // Txn pointer
strFileRes.c_str(), // Filename
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/test/wallet_test_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WalletTestingSetup::WalletTestingSetup(const std::string &chainName) :

bool fFirstRun;
std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, "wallet_test.dat"));
pwalletMain = std::unique_ptr<CWallet>(new CWallet(std::move(dbw)));
pwalletMain = MakeUnique<CWallet>(std::move(dbw));
pwalletMain->LoadWallet(fFirstRun);
RegisterValidationInterface(pwalletMain.get());

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4672,7 +4672,7 @@ CWallet* CWallet:: CreateWalletFromFile(const std::string walletFile)
uiInterface.InitMessage(_("Zapping all transactions from wallet..."));

std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, walletFile));
std::unique_ptr<CWallet> tempWallet(new CWallet(std::move(dbw)));
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(std::move(dbw));
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
if (nZapWalletRet != DB_LOAD_OK) {
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
Expand Down

0 comments on commit a4e806f

Please sign in to comment.