aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-07-13 21:46:25 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-08-05 10:27:53 +0200
commitb9870c920dc475ec759eaf7339ea42aecba92138 (patch)
tree764decc38fda125d083a3787311a877def5faf82 /src
parent532ee812a499e13b123af6b8415d8de1f3804f0f (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/dbwrapper.cpp12
-rw-r--r--src/dbwrapper.h11
2 files changed, 14 insertions, 9 deletions
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp
index b909ce75b5..b74c645b8f 100644
--- a/src/dbwrapper.cpp
+++ b/src/dbwrapper.cpp
@@ -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}
{
diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index 81c75f651e..61f5003db7 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -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();
}