Skip to content

Commit b9870c9

Browse files
committed
refactor: Split dbwrapper CDBatch::Erase implementation
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
1 parent 532ee81 commit b9870c9

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/dbwrapper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ void CDBBatch::WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue)
152152
size_estimate += 3 + (slKey.size() > 127) + slKey.size() + (slValue.size() > 127) + slValue.size();
153153
}
154154

155+
void CDBBatch::EraseImpl(Span<const std::byte> ssKey)
156+
{
157+
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
158+
batch.Delete(slKey);
159+
// LevelDB serializes erases as:
160+
// - byte: header
161+
// - varint: key length
162+
// - byte[]: key
163+
// The formula below assumes the key is less than 16kB.
164+
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
165+
}
166+
155167
CDBWrapper::CDBWrapper(const DBParams& params)
156168
: m_name{fs::PathToString(params.path.stem())}, m_path{params.path}, m_is_memory{params.memory_only}
157169
{

src/dbwrapper.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class CDBBatch
9898
size_t size_estimate{0};
9999

100100
void WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue);
101+
void EraseImpl(Span<const std::byte> ssKey);
101102

102103
public:
103104
/**
@@ -128,15 +129,7 @@ class CDBBatch
128129
{
129130
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
130131
ssKey << key;
131-
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
132-
133-
batch.Delete(slKey);
134-
// LevelDB serializes erases as:
135-
// - byte: header
136-
// - varint: key length
137-
// - byte[]: key
138-
// The formula below assumes the key is less than 16kB.
139-
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
132+
EraseImpl(ssKey);
140133
ssKey.clear();
141134
}
142135

0 commit comments

Comments
 (0)