BAN: String now uses union for its sso storage

This allows String to shrink by 8 bytes since Variant's 8 index is
no longer stored in here.

This required me to make Strings max size one bit less, but that
should still be fine. There should never be strings with size of
over half of the computer's address space.
This commit is contained in:
2023-10-30 11:13:16 +02:00
parent a63006afaf
commit d5e0900cbb
2 changed files with 43 additions and 40 deletions

View File

@@ -82,17 +82,21 @@ namespace BAN
private:
struct SSOStorage
{
char storage[sso_capacity + 1] {};
char data[sso_capacity + 1] {};
};
struct GeneralStorage
{
size_type capacity { 0 };
char* data;
size_type capacity { 0 };
char* data { nullptr };
};
private:
Variant<SSOStorage, GeneralStorage> m_storage { SSOStorage() };
size_type m_size { 0 };
union {
SSOStorage sso_storage;
GeneralStorage general_storage;
} m_storage { .sso_storage = SSOStorage() };
size_type m_size : sizeof(size_type) * 8 - 1 { 0 };
size_type m_has_sso : 1 { true };
};
template<typename... Args>