Browse Source

Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...))

0.16
practicalswift 7 years ago
parent
commit
3e09b390b4
  1. 2
      src/httprpc.cpp
  2. 6
      src/net.cpp
  3. 4
      src/test/dbwrapper_tests.cpp
  4. 4
      src/wallet/db.cpp
  5. 2
      src/wallet/test/wallet_test_fixture.cpp
  6. 2
      src/wallet/wallet.cpp

2
src/httprpc.cpp

@ -238,7 +238,7 @@ bool StartHTTPRPC()
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
#endif #endif
assert(EventBase()); assert(EventBase());
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase())); httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
RPCSetTimerInterface(httpRPCTimerInterface.get()); RPCSetTimerInterface(httpRPCTimerInterface.get());
return true; return true;
} }

6
src/net.cpp

@ -2327,11 +2327,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
if (semOutbound == nullptr) { if (semOutbound == nullptr) {
// initialize semaphore // 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) { if (semAddnode == nullptr) {
// initialize semaphore // initialize semaphore
semAddnode = std::unique_ptr<CSemaphore>(new CSemaphore(nMaxAddnode)); semAddnode = MakeUnique<CSemaphore>(nMaxAddnode);
} }
// //
@ -2741,7 +2741,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nNextInvSend = 0; nNextInvSend = 0;
fRelayTxes = false; fRelayTxes = false;
fSentAddr = false; fSentAddr = false;
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter()); pfilter = MakeUnique<CBloomFilter>();
timeLastMempoolReq = 0; timeLastMempoolReq = 0;
nLastBlockTime = 0; nLastBlockTime = 0;
nLastTXTime = 0; nLastTXTime = 0;

4
src/test/dbwrapper_tests.cpp

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

4
src/wallet/db.cpp

@ -222,7 +222,7 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
} }
LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size()); 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 int ret = pdbCopy->open(nullptr, // Txn pointer
filename.c_str(), // Filename filename.c_str(), // Filename
"main", // Logical db name "main", // Logical db name
@ -522,7 +522,7 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
std::string strFileRes = strFile + ".rewrite"; std::string strFileRes = strFile + ".rewrite";
{ // surround usage of db with extra {} { // surround usage of db with extra {}
CDB db(dbw, "r"); 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 int ret = pdbCopy->open(nullptr, // Txn pointer
strFileRes.c_str(), // Filename strFileRes.c_str(), // Filename

2
src/wallet/test/wallet_test_fixture.cpp

@ -17,7 +17,7 @@ WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
bool fFirstRun; bool fFirstRun;
std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, "wallet_test.dat")); 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); pwalletMain->LoadWallet(fFirstRun);
RegisterValidationInterface(pwalletMain.get()); RegisterValidationInterface(pwalletMain.get());

2
src/wallet/wallet.cpp

@ -3806,7 +3806,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
uiInterface.InitMessage(_("Zapping all transactions from wallet...")); uiInterface.InitMessage(_("Zapping all transactions from wallet..."));
std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, walletFile)); 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); DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
if (nZapWalletRet != DB_LOAD_OK) { if (nZapWalletRet != DB_LOAD_OK) {
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile)); InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));

Loading…
Cancel
Save