aboutsummaryrefslogtreecommitdiff
path: root/src/dbwrapper.h
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-07-22 16:07:29 +0200
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-07-24 15:32:35 +0200
commitfa9108f85afdc926fd6a8b96cc2acff7ca25d7a8 (patch)
tree669d4ff3edc8e863d397bf2e9d20313be4a794cb /src/dbwrapper.h
parent3333f950d49f13662842650ae76599a0dff052eb (diff)
refactor: Use reinterpret_cast where appropriate
Also, wrap reinterpret_cast into a CharCast to ensure it is only called on byte pointers.
Diffstat (limited to 'src/dbwrapper.h')
-rw-r--r--src/dbwrapper.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index 35782edca6..4ae2106211 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -54,6 +54,8 @@ 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:
@@ -113,12 +115,12 @@ public:
{
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
- leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
+ leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
ssValue << value;
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
- leveldb::Slice slValue((const char*)ssValue.data(), ssValue.size());
+ leveldb::Slice slValue(CharCast(ssValue.data()), ssValue.size());
batch.Put(slKey, slValue);
// LevelDB serializes writes as:
@@ -138,7 +140,7 @@ public:
{
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
- leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
+ leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
batch.Delete(slKey);
// LevelDB serializes erases as:
@@ -177,7 +179,7 @@ public:
DataStream ssKey{};
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
- leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
+ leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
piter->Seek(slKey);
}
@@ -265,7 +267,7 @@ public:
DataStream ssKey{};
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
- leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
+ leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
std::string strValue;
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
@@ -307,7 +309,7 @@ public:
DataStream ssKey{};
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
- leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
+ leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
std::string strValue;
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
@@ -351,8 +353,8 @@ public:
ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey1 << key_begin;
ssKey2 << key_end;
- leveldb::Slice slKey1((const char*)ssKey1.data(), ssKey1.size());
- leveldb::Slice slKey2((const char*)ssKey2.data(), ssKey2.size());
+ 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);