summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2023-05-17 07:57:56 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-17 09:23:46 +0000
commitfa994d0377ddc7a10b760a5bde75239d76b7f1e7 (patch)
tree5fadecff489ed659f8ba55c525523d1ab8308710
parentef7b01c09dad0dd01b1a4ffecfef623de2b58cd9 (diff)
downloadmongo-fa994d0377ddc7a10b760a5bde75239d76b7f1e7.tar.gz
SERVER-76788 elide trivial Decoration constructors
-rw-r--r--src/mongo/util/decoration_container.h2
-rw-r--r--src/mongo/util/decoration_registry.h14
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>(),
&copyConstructAt<T>,
&copyAssignAt<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;