diff --git a/Foundation/include/Poco/Any.h b/Foundation/include/Poco/Any.h index 7e0bd04f08..667997b09e 100644 --- a/Foundation/include/Poco/Any.h +++ b/Foundation/include/Poco/Any.h @@ -83,7 +83,7 @@ union Placeholder // Forces to use optimised memset internally // https://travisdowns.github.io/blog/2020/01/20/zero.html std::fill(std::begin(holder), std::end(holder), static_cast(0)); - setAllocation(Allocation::EMPTY); + setAllocation(Allocation::POCO_ANY_EMPTY); } ~Placeholder() @@ -104,12 +104,12 @@ union Placeholder bool isEmpty() const { - return holder[SizeV] == Allocation::EMPTY; + return holder[SizeV] == Allocation::POCO_ANY_EMPTY; } bool isLocal() const { - return holder[SizeV] == Allocation::LOCAL; + return holder[SizeV] == Allocation::POCO_ANY_LOCAL; } template(holder)) T(value); - setAllocation(Allocation::LOCAL); + setAllocation(Allocation::POCO_ANY_LOCAL); return reinterpret_cast(holder); } @@ -128,7 +128,7 @@ union Placeholder { erase(); pHolder = new T(value); - setAllocation(Allocation::EXTERNAL); + setAllocation(Allocation::POCO_ANY_EXTERNAL); return pHolder; } @@ -144,10 +144,11 @@ union Placeholder using AlignerType = std::max_align_t; static_assert(sizeof(AlignerType) <= SizeV + 1, "Aligner type is bigger than the actual storage, so SizeV should be made bigger otherwise you simply waste unused memory."); - enum Allocation : unsigned char { - EMPTY = 0, - LOCAL = 1, - EXTERNAL = 2 + enum Allocation : unsigned char + { + POCO_ANY_EMPTY = 0, + POCO_ANY_LOCAL = 1, + POCO_ANY_EXTERNAL = 2 }; void setAllocation(Allocation state) const @@ -159,15 +160,15 @@ union Placeholder { switch (holder[SizeV]) { - case Allocation::EMPTY: + case Allocation::POCO_ANY_EMPTY: break; - case Allocation::LOCAL: + case Allocation::POCO_ANY_LOCAL: { auto* h { reinterpret_cast(holder) }; h->~PlaceholderT(); } break; - case Allocation::EXTERNAL: + case Allocation::POCO_ANY_EXTERNAL: { auto* h { pHolder }; pHolder = nullptr; @@ -183,7 +184,7 @@ union Placeholder // Force to use optimised memset internally std::fill(std::begin(holder), std::end(holder), static_cast(0)); } - setAllocation(Allocation::EMPTY); + setAllocation(Allocation::POCO_ANY_EMPTY); } mutable unsigned char holder[SizeV+1]; @@ -279,8 +280,11 @@ class Any } ~Any() = default; - /// Destructor. If Any is locally held, calls ValueHolder destructor; - /// otherwise, deletes the placeholder from the heap. + /// Destructor. + /// Small Object Optimization mode behavior: + /// Invokes the Placeholder destructor, which calls the + /// ValueHolder destructor explicitly (locally held Any), or + /// deletes the ValueHolder heap memory (heap-allocated Any). Any& swap(Any& other) noexcept /// Swaps the content of the two Anys.