From b0875eb3fea0934f3a6651fbc22aac12e33e15e5 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 24 Aug 2014 02:08:05 +0200 Subject: Allow BatchWrite to destroy its input, reducing copying --- src/txdb.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/txdb.cpp') 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); -- cgit v1.2.3