Skip to content

Commit 01c3dc9

Browse files
committed
Reserve batch size
1 parent e48a266 commit 01c3dc9

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/dbwrapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ void CDBBatch::Clear()
166166
{
167167
m_impl_batch->batch.Clear();
168168
}
169+
void CDBBatch::Reserve(size_t size) const
170+
{
171+
m_impl_batch->batch.Reserve(size);
172+
}
169173
size_t CDBBatch::ApproximateSize() const
170174
{
171175
return m_impl_batch->batch.ApproximateSize();

src/leveldb/db/write_batch.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void WriteBatch::Clear() {
3737
rep_.resize(kHeader);
3838
}
3939

40+
void WriteBatch::Reserve(size_t size) {
41+
rep_.reserve(size);
42+
}
43+
4044
size_t WriteBatch::ApproximateSize() const { return rep_.size(); }
4145

4246
Status WriteBatch::Iterate(Handler* handler) const {

src/leveldb/include/leveldb/write_batch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class LEVELDB_EXPORT WriteBatch {
5656
// Clear all updates buffered in this batch.
5757
void Clear();
5858

59+
// Preallocate memory for a batch containing a sequence of updates.
60+
void Reserve(size_t size);
61+
5962
// The size of the database changes caused by this batch.
6063
//
6164
// This number is tied to implementation details, and may change across

src/txdb.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const {
9292

9393
bool CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashBlock) {
9494
CDBBatch batch(*m_db);
95+
batch.Reserve(m_options.batch_write_bytes);
9596

9697
size_t count = 0;
9798
size_t changed = 0;

0 commit comments

Comments
 (0)