Skip to content

Commit ef941ff

Browse files
committed
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.
1 parent b7a1ab5 commit ef941ff

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/dbwrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ Span<const std::byte> CDBIterator::GetKeyImpl() const
317317
return MakeByteSpan(piter->key());
318318
}
319319

320+
Span<const std::byte> CDBIterator::GetValueImpl() const
321+
{
322+
return MakeByteSpan(piter->value());
323+
}
324+
320325
CDBIterator::~CDBIterator() { delete piter; }
321326
bool CDBIterator::Valid() const { return piter->Valid(); }
322327
void CDBIterator::SeekToFirst() { piter->SeekToFirst(); }

src/dbwrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <cstdint>
1717
#include <exception>
1818
#include <leveldb/db.h>
19-
#include <leveldb/iterator.h>
2019
#include <leveldb/options.h>
2120
#include <leveldb/slice.h>
2221
#include <leveldb/status.h>
@@ -27,6 +26,7 @@
2726
#include <vector>
2827
namespace leveldb {
2928
class Env;
29+
class Iterator;
3030
}
3131

3232
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
@@ -142,6 +142,7 @@ class CDBIterator
142142

143143
void SeekImpl(Span<const std::byte> ssKey);
144144
Span<const std::byte> GetKeyImpl() const;
145+
Span<const std::byte> GetValueImpl() const;
145146

146147
public:
147148

@@ -177,9 +178,8 @@ class CDBIterator
177178
}
178179

179180
template<typename V> bool GetValue(V& value) {
180-
leveldb::Slice slValue = piter->value();
181181
try {
182-
CDataStream ssValue{MakeByteSpan(slValue), SER_DISK, CLIENT_VERSION};
182+
CDataStream ssValue{GetValueImpl(), SER_DISK, CLIENT_VERSION};
183183
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
184184
ssValue >> value;
185185
} catch (const std::exception&) {

0 commit comments

Comments
 (0)