Skip to content

Commit

Permalink
enh(Any): reduce memory usage for small object optimisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
matejk committed Dec 20, 2024
1 parent c19156e commit 4f4520f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Foundation/include/Poco/Any.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -168,6 +168,7 @@ union Placeholder
break;
case Allocation::POCO_ANY_LOCAL:
{
// Do not deallocate, just explicitly call destructor
auto* h { reinterpret_cast<PlaceholderT*>(holder) };
h->~PlaceholderT();
}
Expand All @@ -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<char>(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

Expand Down Expand Up @@ -239,8 +244,8 @@ union Placeholder
}

private:
#endif // POCO_NO_SOO
PlaceholderT* pHolder;
#endif // POCO_NO_SOO
};


Expand Down

0 comments on commit 4f4520f

Please sign in to comment.