From b7a1ab5cb4e60230f62c94efb3a10d07c9af4883 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Fri, 14 Jul 2023 11:21:26 +0200 Subject: [PATCH] refactor: Split dbwrapper CDBIterator::GetKey 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 | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 87d46f31925..dbf1d18de2b 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -312,6 +312,11 @@ void CDBIterator::SeekImpl(Span ssKey) piter->Seek(slKey); } +Span CDBIterator::GetKeyImpl() const +{ + return MakeByteSpan(piter->key()); +} + 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 aa2b31b160e..9aadeef76db 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -141,6 +141,7 @@ private: leveldb::Iterator *piter; void SeekImpl(Span ssKey); + Span GetKeyImpl() const; public: @@ -166,9 +167,8 @@ public: void Next(); template bool GetKey(K& key) { - leveldb::Slice slKey = piter->key(); try { - DataStream ssKey{MakeByteSpan(slKey)}; + DataStream ssKey{GetKeyImpl()}; ssKey >> key; } catch (const std::exception&) { return false;