Skip to content

Commit 3e09b39

Browse files
Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...))
1 parent 8617989 commit 3e09b39

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

src/httprpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ bool StartHTTPRPC()
238238
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
239239
#endif
240240
assert(EventBase());
241-
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase()));
241+
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
242242
RPCSetTimerInterface(httpRPCTimerInterface.get());
243243
return true;
244244
}

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,11 +2327,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
23272327

23282328
if (semOutbound == nullptr) {
23292329
// initialize semaphore
2330-
semOutbound = std::unique_ptr<CSemaphore>(new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)));
2330+
semOutbound = MakeUnique<CSemaphore>(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
23312331
}
23322332
if (semAddnode == nullptr) {
23332333
// initialize semaphore
2334-
semAddnode = std::unique_ptr<CSemaphore>(new CSemaphore(nMaxAddnode));
2334+
semAddnode = MakeUnique<CSemaphore>(nMaxAddnode);
23352335
}
23362336

23372337
//
@@ -2741,7 +2741,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27412741
nNextInvSend = 0;
27422742
fRelayTxes = false;
27432743
fSentAddr = false;
2744-
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter());
2744+
pfilter = MakeUnique<CBloomFilter>();
27452745
timeLastMempoolReq = 0;
27462746
nLastBlockTime = 0;
27472747
nLastTXTime = 0;

src/test/dbwrapper_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
125125
create_directories(ph);
126126

127127
// Set up a non-obfuscated wrapper to write some initial data.
128-
std::unique_ptr<CDBWrapper> dbw = std::unique_ptr<CDBWrapper>(new CDBWrapper(ph, (1 << 10), false, false, false));
128+
std::unique_ptr<CDBWrapper> dbw = MakeUnique<CDBWrapper>(ph, (1 << 10), false, false, false);
129129
char key = 'k';
130130
uint256 in = InsecureRand256();
131131
uint256 res;
@@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
166166
create_directories(ph);
167167

168168
// Set up a non-obfuscated wrapper to write some initial data.
169-
std::unique_ptr<CDBWrapper> dbw = std::unique_ptr<CDBWrapper>(new CDBWrapper(ph, (1 << 10), false, false, false));
169+
std::unique_ptr<CDBWrapper> dbw = MakeUnique<CDBWrapper>(ph, (1 << 10), false, false, false);
170170
char key = 'k';
171171
uint256 in = InsecureRand256();
172172
uint256 res;

src/wallet/db.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
222222
}
223223
LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());
224224

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

527527
int ret = pdbCopy->open(nullptr, // Txn pointer
528528
strFileRes.c_str(), // Filename

src/wallet/test/wallet_test_fixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
1717

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

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3806,7 +3806,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
38063806
uiInterface.InitMessage(_("Zapping all transactions from wallet..."));
38073807

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

0 commit comments

Comments
 (0)