From ef941ff1281e76308c3e746e592375bec023e9e4 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Fri, 14 Jul 2023 11:30:52 +0200 Subject: [PATCH] refactor: Split dbwrapper CDBIterator::GetValue 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. --- src/dbwrapper.cpp | 5 +++++ src/dbwrapper.h | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index dbf1d18de2b..2f0b9a5ff34 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -317,6 +317,11 @@ Span CDBIterator::GetKeyImpl() const return MakeByteSpan(piter->key()); } +Span CDBIterator::GetValueImpl() const +{ + return MakeByteSpan(piter->value()); +} + CDBIterator::~CDBIterator() { delete piter; } bool CDBIterator::Valid() const { return piter->Valid(); } void CDBIterator::SeekToFirst() { piter->SeekToFirst(); } diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 9aadeef76db..2e6cc4d81e0 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include namespace leveldb { class Env; +class Iterator; } static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; @@ -142,6 +142,7 @@ private: void SeekImpl(Span ssKey); Span GetKeyImpl() const; + Span GetValueImpl() const; public: @@ -177,9 +178,8 @@ public: } template bool GetValue(V& value) { - leveldb::Slice slValue = piter->value(); try { - CDataStream ssValue{MakeByteSpan(slValue), SER_DISK, CLIENT_VERSION}; + CDataStream ssValue{GetValueImpl(), SER_DISK, CLIENT_VERSION}; ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent)); ssValue >> value; } catch (const std::exception&) {