diff options
-rw-r--r-- | src/mongo/util/decoration_container.h | 2 | ||||
-rw-r--r-- | src/mongo/util/decoration_registry.h | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/mongo/util/decoration_container.h b/src/mongo/util/decoration_container.h index 4b2f7bf0619..67a76730a16 100644 --- a/src/mongo/util/decoration_container.h +++ b/src/mongo/util/decoration_container.h @@ -97,7 +97,7 @@ public: explicit DecorationContainer(Decorable<DecoratedType>* const decorated, const DecorationRegistry<DecoratedType>* const registry) : _registry(registry), - _decorationData(new unsigned char[registry->getDecorationBufferSizeBytes()]) { + _decorationData(new unsigned char[registry->getDecorationBufferSizeBytes()]{}) { // Because the decorations live in the externally allocated storage buffer at // `_decorationData`, there needs to be a way to get back from a known location within this // buffer to the type which owns those decorations. We place a pointer to ourselves, a diff --git a/src/mongo/util/decoration_registry.h b/src/mongo/util/decoration_registry.h index 4720d5fc9ed..5bac5979830 100644 --- a/src/mongo/util/decoration_registry.h +++ b/src/mongo/util/decoration_registry.h @@ -71,7 +71,7 @@ public: typename DecorationContainer<DecoratedType>::template DecorationDescriptorWithType<T>( std::move(declareDecoration(sizeof(T), std::alignment_of<T>::value, - &constructAt<T>, + getConstructorFn<T>(), nullptr, nullptr, getDestructorFn<T>()))); @@ -93,7 +93,7 @@ public: typename DecorationContainer<DecoratedType>::template DecorationDescriptorWithType<T>( std::move(declareDecoration(sizeof(T), std::alignment_of<T>::value, - &constructAt<T>, + getConstructorFn<T>(), ©ConstructAt<T>, ©AssignAt<T>, getDestructorFn<T>()))); @@ -131,6 +131,8 @@ public: using std::cend; for (; iter != cend(_decorationInfo); ++iter) { + if (!iter->constructor) + continue; iter->constructor(container->getDecoration(iter->descriptor)); } @@ -271,6 +273,14 @@ private: } template <typename T> + static constexpr DecorationConstructorFn getConstructorFn() { + if constexpr (std::is_trivially_constructible_v<T>) + return nullptr; + else + return &constructAt<T>; + } + + template <typename T> static constexpr DecorationDestructorFn getDestructorFn() { if constexpr (std::is_trivially_destructible_v<T>) return nullptr; |