diff --git a/options/customizable_test.cc b/options/customizable_test.cc index ffed2efd29..9d3c86c620 100644 --- a/options/customizable_test.cc +++ b/options/customizable_test.cc @@ -9,11 +9,9 @@ #include "rocksdb/customizable.h" -#include #include #include #include -#include #include #include @@ -211,49 +209,32 @@ struct SimpleOptions { TestCustomizable* cp = nullptr; }; -static std::unordered_map simple_option_info; - -template -static int dynamic_unsafe_offsetof(const T& instance, const F& field) { - const char* instance_addr = - reinterpret_cast(std::addressof(instance)); - const char* field_addr = reinterpret_cast(std::addressof(field)); - assert(field_addr >= instance_addr); - const size_t offset = field_addr - instance_addr; - assert(offset < sizeof(instance)); - return offset; -} +static std::unordered_map simple_option_info = { +#ifndef ROCKSDB_LITE + {"bool", + {offsetof(struct SimpleOptions, b), OptionType::kBoolean, + OptionVerificationType::kNormal, OptionTypeFlags::kNone}}, + {"unique", + OptionTypeInfo::AsCustomUniquePtr( + offsetof(struct SimpleOptions, cu), OptionVerificationType::kNormal, + OptionTypeFlags::kAllowNull)}, + {"shared", + OptionTypeInfo::AsCustomSharedPtr( + offsetof(struct SimpleOptions, cs), OptionVerificationType::kNormal, + OptionTypeFlags::kAllowNull)}, + {"pointer", + OptionTypeInfo::AsCustomRawPtr( + offsetof(struct SimpleOptions, cp), OptionVerificationType::kNormal, + OptionTypeFlags::kAllowNull)}, +#endif // ROCKSDB_LITE +}; class SimpleConfigurable : public Configurable { private: SimpleOptions simple_; public: - SimpleConfigurable() { -#ifndef ROCKSDB_LITE - SimpleOptions so; - simple_option_info.emplace( - "bool", OptionTypeInfo{ - dynamic_unsafe_offsetof(so, so.b), OptionType::kBoolean, - OptionVerificationType::kNormal, OptionTypeFlags::kNone}); - simple_option_info.emplace( - "unique", - OptionTypeInfo::AsCustomUniquePtr( - dynamic_unsafe_offsetof(so, so.cu), OptionVerificationType::kNormal, - OptionTypeFlags::kAllowNull)); - simple_option_info.emplace( - "shared", - OptionTypeInfo::AsCustomSharedPtr( - dynamic_unsafe_offsetof(so, so.cs), OptionVerificationType::kNormal, - OptionTypeFlags::kAllowNull)); - simple_option_info.emplace( - "pointer", - OptionTypeInfo::AsCustomRawPtr( - dynamic_unsafe_offsetof(so, so.cp), OptionVerificationType::kNormal, - OptionTypeFlags::kAllowNull)); -#endif // ROCKSDB_LITE - RegisterOptions(&simple_, &simple_option_info); - } + SimpleConfigurable() { RegisterOptions(&simple_, &simple_option_info); } explicit SimpleConfigurable( const std::unordered_map* map) {