diff --git a/Foundation/include/Poco/Any.h b/Foundation/include/Poco/Any.h index 492fc501c0..f0c4621d0c 100644 --- a/Foundation/include/Poco/Any.h +++ b/Foundation/include/Poco/Any.h @@ -78,7 +78,7 @@ union Placeholder #ifndef POCO_NO_SOO - Placeholder(): pHolder(nullptr) + Placeholder() { // Forces to use optimised memset internally // https://travisdowns.github.io/blog/2020/01/20/zero.html @@ -168,6 +168,7 @@ union Placeholder break; case Allocation::POCO_ANY_LOCAL: { + // Do not deallocate, just explicitly call destructor auto* h { reinterpret_cast(holder) }; h->~PlaceholderT(); } @@ -183,16 +184,20 @@ union Placeholder poco_bugcheck(); break; } + setAllocation(Allocation::POCO_ANY_EMPTY); if (clear) { // Force to use optimised memset internally std::fill(std::begin(holder), std::end(holder), static_cast(0)); } - setAllocation(Allocation::POCO_ANY_EMPTY); } - mutable unsigned char holder[SizeV+1]; - AlignerType aligner; + // Either store small object or a pointer to a placeholder + union + { + mutable unsigned char holder[SizeV+1]; + PlaceholderT* pHolder; + }; #else // POCO_NO_SOO @@ -239,8 +244,8 @@ union Placeholder } private: -#endif // POCO_NO_SOO PlaceholderT* pHolder; +#endif // POCO_NO_SOO };