diff options
| author | Billy Donahue <billy.donahue@mongodb.com> | 2022-09-20 04:15:15 +0000 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-20 05:21:29 +0000 |
| commit | 0e99736add3d834bd0094a4f4aac733529a1ad76 (patch) | |
| tree | 1dc4e740d8f289056d936f80484892542ce66ae8 /src | |
| parent | 95b09b11518fa8e63cc74da178a01932d7d134ea (diff) | |
| download | mongo-0e99736add3d834bd0094a4f4aac733529a1ad76.tar.gz | |
SERVER-69383 elide trivial destructors for Decorations
Diffstat (limited to 'src')
| -rw-r--r-- | src/mongo/util/decoration_registry.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/util/decoration_registry.h b/src/mongo/util/decoration_registry.h index bd47fa96abd..0fc05a1efdd 100644 --- a/src/mongo/util/decoration_registry.h +++ b/src/mongo/util/decoration_registry.h @@ -74,7 +74,7 @@ public: &constructAt<T>, nullptr, nullptr, - &destroyAt<T>))); + getDestructorFn<T>()))); } /** @@ -96,7 +96,7 @@ public: &constructAt<T>, ©ConstructAt<T>, ©AssignAt<T>, - &destroyAt<T>))); + getDestructorFn<T>()))); } size_t getDecorationBufferSizeBytes() const { @@ -119,6 +119,8 @@ public: std::for_each(std::make_reverse_iterator(iter), crend(this->_decorationInfo), [&](auto&& decoration) { + if (!decoration.destructor) + return; decoration.destructor( container->getDecoration(decoration.descriptor)); }); @@ -196,6 +198,8 @@ public: */ void destroy(DecorationContainer<DecoratedType>* const container) const noexcept try { std::for_each(_decorationInfo.rbegin(), _decorationInfo.rend(), [&](auto&& decoration) { + if (!decoration.destructor) + return; decoration.destructor(container->getDecoration(decoration.descriptor)); }); } catch (...) { @@ -266,6 +270,14 @@ private: static_cast<T*>(location)->~T(); } + template <typename T> + static constexpr DecorationDestructorFn getDestructorFn() { + if constexpr (std::is_trivially_destructible_v<T>) + return nullptr; + else + return &destroyAt<T>; + } + /** * Declares a decoration with given "constructor" and "destructor" functions, * of "sizeBytes" bytes. |
