diff options
author | TheCharlatan <seb.kung@gmail.com> | 2023-07-14 12:04:41 +0200 |
---|---|---|
committer | TheCharlatan <seb.kung@gmail.com> | 2023-08-05 10:43:01 +0200 |
commit | c534a615e93452a5f509aaf5f68c600391a98d6a (patch) | |
tree | 5ba2aa8df4dd8e0bfa087bfcc458e134ea6dbe1a /src/dbwrapper.cpp | |
parent | 586448888b72f7c87db4dcd30fc4e4044afae13b (diff) |
refactor: Split dbwrapper CDBWrapper::EstimateSize implementation
Keep the generic serialization in the header, while moving
leveldb-specifics to the implementation file.
Since CharCast is no longer needed in the header, move it 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/dbwrapper.cpp')
-rw-r--r-- | src/dbwrapper.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index fe0a2e66f2..58fd47ce1c 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -33,6 +33,8 @@ #include <optional> #include <utility> +static auto CharCast(const std::byte* data) { return reinterpret_cast<const char*>(data); } + bool DestroyDB(const std::string& path_str) { return leveldb::DestroyDB(path_str, {}).ok(); @@ -340,6 +342,16 @@ bool CDBWrapper::ExistsImpl(Span<const std::byte> ssKey) const return true; } +size_t CDBWrapper::EstimateSizeImpl(Span<const std::byte> ssKey1, Span<const std::byte> ssKey2) const +{ + leveldb::Slice slKey1(CharCast(ssKey1.data()), ssKey1.size()); + leveldb::Slice slKey2(CharCast(ssKey2.data()), ssKey2.size()); + uint64_t size = 0; + leveldb::Range range(slKey1, slKey2); + pdb->GetApproximateSizes(&range, 1, &size); + return size; +} + bool CDBWrapper::IsEmpty() { std::unique_ptr<CDBIterator> it(NewIterator()); |