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.h | |
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.h')
-rw-r--r-- | src/dbwrapper.h | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 9756207aec..fa7b6397cb 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -12,17 +12,15 @@ #include <util/fs.h> #include <cstddef> -#include <cstdint> #include <exception> -#include <leveldb/db.h> #include <leveldb/options.h> -#include <leveldb/slice.h> #include <memory> #include <optional> #include <stdexcept> #include <string> #include <vector> namespace leveldb { +class DB; class Env; } @@ -52,8 +50,6 @@ struct DBParams { DBOptions options{}; }; -inline auto CharCast(const std::byte* data) { return reinterpret_cast<const char*>(data); } - class dbwrapper_error : public std::runtime_error { public: @@ -231,6 +227,7 @@ private: std::optional<std::string> ReadImpl(Span<const std::byte> ssKey) const; bool ExistsImpl(Span<const std::byte> ssKey) const; + size_t EstimateSizeImpl(Span<const std::byte> ssKey1, Span<const std::byte> ssKey2) const; public: CDBWrapper(const DBParams& params); @@ -312,12 +309,7 @@ public: ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey1 << key_begin; ssKey2 << key_end; - 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; + return EstimateSizeImpl(ssKey1, ssKey2); } }; |