mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
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.
This commit is contained in:
parent
532ee812a4
commit
b9870c920d
2 changed files with 14 additions and 9 deletions
|
@ -152,6 +152,18 @@ void CDBBatch::WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue)
|
|||
size_estimate += 3 + (slKey.size() > 127) + slKey.size() + (slValue.size() > 127) + slValue.size();
|
||||
}
|
||||
|
||||
void CDBBatch::EraseImpl(Span<const std::byte> ssKey)
|
||||
{
|
||||
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
||||
batch.Delete(slKey);
|
||||
// LevelDB serializes erases as:
|
||||
// - byte: header
|
||||
// - varint: key length
|
||||
// - byte[]: key
|
||||
// The formula below assumes the key is less than 16kB.
|
||||
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
|
||||
}
|
||||
|
||||
CDBWrapper::CDBWrapper(const DBParams& params)
|
||||
: m_name{fs::PathToString(params.path.stem())}, m_path{params.path}, m_is_memory{params.memory_only}
|
||||
{
|
||||
|
|
|
@ -98,6 +98,7 @@ private:
|
|||
size_t size_estimate{0};
|
||||
|
||||
void WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue);
|
||||
void EraseImpl(Span<const std::byte> ssKey);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -128,15 +129,7 @@ public:
|
|||
{
|
||||
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
|
||||
ssKey << key;
|
||||
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
||||
|
||||
batch.Delete(slKey);
|
||||
// LevelDB serializes erases as:
|
||||
// - byte: header
|
||||
// - varint: key length
|
||||
// - byte[]: key
|
||||
// The formula below assumes the key is less than 16kB.
|
||||
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
|
||||
EraseImpl(ssKey);
|
||||
ssKey.clear();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue