aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-08-24 02:08:05 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-08-24 02:08:33 +0200
commitb0875eb3fea0934f3a6651fbc22aac12e33e15e5 (patch)
tree24d1ee392c0b29a61e0b4c09bae780d6ae35866d /src/txdb.cpp
parent5cd00bc8cb6820d3b41bea329fcf0c26c03db64a (diff)
Allow BatchWrite to destroy its input, reducing copying
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index d3d05c58d7..7c0683aaf3 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -54,12 +54,15 @@ bool CCoinsViewDB::SetBestBlock(const uint256 &hashBlock) {
return db.WriteBatch(batch);
}
-bool CCoinsViewDB::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock) {
+bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
LogPrint("coindb", "Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
CLevelDBBatch batch;
- for (CCoinsMap::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
+ for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
BatchWriteCoins(batch, it->first, it->second);
+ CCoinsMap::iterator itOld = it++;
+ mapCoins.erase(itOld);
+ }
if (hashBlock != uint256(0))
BatchWriteHashBestChain(batch, hashBlock);