aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-06-20 08:55:07 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-06-20 08:42:35 -0400
commitfa8a341b88cabfd7f8d702db7cb9972b0804bf2a (patch)
treed3799d88cba30531c5503b089025ac68126567d8 /src
parentfa021e9a5b7e930a3db0febb416942dea3a90a8f (diff)
wallet: Replace CDataStream& with CDataStream&& where appropriate
The keys and values are only to be used once because their memory is set to zero. Make that explicit by moving the bytes into the lower level methods.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/bdb.cpp8
-rw-r--r--src/wallet/bdb.h16
2 files changed, 12 insertions, 12 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp
index a3a56aa51c..267b147f38 100644
--- a/src/wallet/bdb.cpp
+++ b/src/wallet/bdb.cpp
@@ -804,7 +804,7 @@ std::string BerkeleyDatabaseVersion()
return DbEnv::version(nullptr, nullptr, nullptr);
}
-bool BerkeleyBatch::ReadKey(CDataStream& key, CDataStream& value)
+bool BerkeleyBatch::ReadKey(CDataStream&& key, CDataStream& value)
{
if (!pdb)
return false;
@@ -820,7 +820,7 @@ bool BerkeleyBatch::ReadKey(CDataStream& key, CDataStream& value)
return false;
}
-bool BerkeleyBatch::WriteKey(CDataStream& key, CDataStream& value, bool overwrite)
+bool BerkeleyBatch::WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite)
{
if (!pdb)
return true;
@@ -835,7 +835,7 @@ bool BerkeleyBatch::WriteKey(CDataStream& key, CDataStream& value, bool overwrit
return (ret == 0);
}
-bool BerkeleyBatch::EraseKey(CDataStream& key)
+bool BerkeleyBatch::EraseKey(CDataStream&& key)
{
if (!pdb)
return false;
@@ -848,7 +848,7 @@ bool BerkeleyBatch::EraseKey(CDataStream& key)
return (ret == 0 || ret == DB_NOTFOUND);
}
-bool BerkeleyBatch::HasKey(CDataStream& key)
+bool BerkeleyBatch::HasKey(CDataStream&& key)
{
if (!pdb)
return false;
diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h
index a2eaf95001..91116afd01 100644
--- a/src/wallet/bdb.h
+++ b/src/wallet/bdb.h
@@ -189,10 +189,10 @@ class BerkeleyBatch
};
private:
- bool ReadKey(CDataStream& key, CDataStream& value);
- bool WriteKey(CDataStream& key, CDataStream& value, bool overwrite=true);
- bool EraseKey(CDataStream& key);
- bool HasKey(CDataStream& key);
+ bool ReadKey(CDataStream&& key, CDataStream& value);
+ bool WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite = true);
+ bool EraseKey(CDataStream&& key);
+ bool HasKey(CDataStream&& key);
protected:
Db* pdb;
@@ -228,7 +228,7 @@ public:
ssKey << key;
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
- if (!ReadKey(ssKey, ssValue)) return false;
+ if (!ReadKey(std::move(ssKey), ssValue)) return false;
try {
ssValue >> value;
return true;
@@ -248,7 +248,7 @@ public:
ssValue.reserve(10000);
ssValue << value;
- return WriteKey(ssKey, ssValue, fOverwrite);
+ return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite);
}
template <typename K>
@@ -258,7 +258,7 @@ public:
ssKey.reserve(1000);
ssKey << key;
- return EraseKey(ssKey);
+ return EraseKey(std::move(ssKey));
}
template <typename K>
@@ -268,7 +268,7 @@ public:
ssKey.reserve(1000);
ssKey << key;
- return HasKey(ssKey);
+ return HasKey(std::move(ssKey));
}
Dbc* GetCursor();