Skip to content

Commit 22d7e70

Browse files
author
Philip Kaufmann
committed
prefer const string& over char* in CDB and CWalletDB constructor
- also make parameter of CDBEnv::CheckpointLSN a constant reference
1 parent 438c7e4 commit 22d7e70

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/db.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive,
215215
}
216216

217217

218-
void CDBEnv::CheckpointLSN(std::string strFile)
218+
void CDBEnv::CheckpointLSN(const std::string& strFile)
219219
{
220220
dbenv.txn_checkpoint(0, 0, 0);
221221
if (fMockDb)
@@ -224,12 +224,12 @@ void CDBEnv::CheckpointLSN(std::string strFile)
224224
}
225225

226226

227-
CDB::CDB(const char *pszFile, const char* pszMode) :
227+
CDB::CDB(const std::string& strFilename, const char* pszMode) :
228228
pdb(NULL), activeTxn(NULL)
229229
{
230230
int ret;
231231
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
232-
if (pszFile == NULL)
232+
if (strFilename.empty())
233233
return;
234234

235235
bool fCreate = strchr(pszMode, 'c') != NULL;
@@ -242,7 +242,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
242242
if (!bitdb.Open(GetDataDir()))
243243
throw runtime_error("CDB : Failed to open database environment.");
244244

245-
strFile = pszFile;
245+
strFile = strFilename;
246246
++bitdb.mapFileUseCount[strFile];
247247
pdb = bitdb.mapDb[strFile];
248248
if (pdb == NULL)
@@ -255,14 +255,14 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
255255
DbMpoolFile*mpf = pdb->get_mpf();
256256
ret = mpf->set_flags(DB_MPOOL_NOFILE, 1);
257257
if (ret != 0)
258-
throw runtime_error(strprintf("CDB : Failed to configure for no temp file backing for database %s", pszFile));
258+
throw runtime_error(strprintf("CDB : Failed to configure for no temp file backing for database %s", strFile));
259259
}
260260

261-
ret = pdb->open(NULL, // Txn pointer
262-
fMockDb ? NULL : pszFile, // Filename
263-
fMockDb ? pszFile : "main", // Logical db name
264-
DB_BTREE, // Database type
265-
nFlags, // Flags
261+
ret = pdb->open(NULL, // Txn pointer
262+
fMockDb ? NULL : strFile.c_str(), // Filename
263+
fMockDb ? strFile.c_str() : "main", // Logical db name
264+
DB_BTREE, // Database type
265+
nFlags, // Flags
266266
0);
267267

268268
if (ret != 0)
@@ -271,7 +271,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
271271
pdb = NULL;
272272
--bitdb.mapFileUseCount[strFile];
273273
strFile = "";
274-
throw runtime_error(strprintf("CDB : Error %d, can't open database %s", ret, pszFile));
274+
throw runtime_error(strprintf("CDB : Error %d, can't open database %s", ret, strFile));
275275
}
276276

277277
if (fCreate && !Exists(string("version")))

src/db.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CDBEnv
6969
bool Open(const boost::filesystem::path &path);
7070
void Close();
7171
void Flush(bool fShutdown);
72-
void CheckpointLSN(std::string strFile);
72+
void CheckpointLSN(const std::string& strFile);
7373

7474
void CloseDb(const std::string& strFile);
7575
bool RemoveDb(const std::string& strFile);
@@ -96,11 +96,13 @@ class CDB
9696
DbTxn *activeTxn;
9797
bool fReadOnly;
9898

99-
explicit CDB(const char* pszFile, const char* pszMode="r+");
99+
explicit CDB(const std::string& strFilename, const char* pszMode="r+");
100100
~CDB() { Close(); }
101+
101102
public:
102103
void Flush();
103104
void Close();
105+
104106
private:
105107
CDB(const CDB&);
106108
void operator=(const CDB&);

src/walletdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CKeyMetadata
7575
class CWalletDB : public CDB
7676
{
7777
public:
78-
CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
78+
CWalletDB(const std::string& strFilename, const char* pszMode = "r+") : CDB(strFilename, pszMode)
7979
{
8080
}
8181
private:

0 commit comments

Comments
 (0)