aboutsummaryrefslogtreecommitdiff
path: root/src/dbwrapper.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2016-12-13 23:53:39 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2016-12-14 00:31:28 -0800
commited5896976a5cb6d893babedec2bc88cb7a251033 (patch)
treef960c5b188d6930c4197d72748d4d049947c03d3 /src/dbwrapper.h
parent26fe5c98ab6a0bcf253467d70ef0d910fedac518 (diff)
Batch construct batches
Reuse the serialization buffers used for constructing the LevelDB write batch. This avoids 2 allocations per utxo write.
Diffstat (limited to 'src/dbwrapper.h')
-rw-r--r--src/dbwrapper.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index 4a79bbd17d..08c72c25dd 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -53,38 +53,41 @@ private:
const CDBWrapper &parent;
leveldb::WriteBatch batch;
+ CDataStream ssKey;
+ CDataStream ssValue;
+
public:
/**
* @param[in] _parent CDBWrapper that this batch is to be submitted to
*/
- CDBBatch(const CDBWrapper &_parent) : parent(_parent) { };
+ CDBBatch(const CDBWrapper &_parent) : parent(_parent), ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION) { };
template <typename K, typename V>
void Write(const K& key, const V& value)
{
- CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
leveldb::Slice slKey(&ssKey[0], ssKey.size());
- CDataStream ssValue(SER_DISK, CLIENT_VERSION);
ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
ssValue << value;
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
leveldb::Slice slValue(&ssValue[0], ssValue.size());
batch.Put(slKey, slValue);
+ ssKey.clear();
+ ssValue.clear();
}
template <typename K>
void Erase(const K& key)
{
- CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
leveldb::Slice slKey(&ssKey[0], ssKey.size());
batch.Delete(slKey);
+ ssKey.clear();
}
};