From 24cd7c8896b2091114e89ffda06b5c63eb2827c7 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Tue, 29 Oct 2024 00:11:13 -0500 Subject: Back out of modified SSO. --- include/fud_string.hpp | 42 ------------------------------------------ source/fud_string.cpp | 6 +++--- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/include/fud_string.hpp b/include/fud_string.hpp index 29b887a..55b1e86 100644 --- a/include/fud_string.hpp +++ b/include/fud_string.hpp @@ -326,57 +326,15 @@ class String { FudStatus resize(size_t newCapacity); - [[nodiscard]] bool optIsLarge() const - { - return (reinterpret_cast(m_allocator) & capacityMask) != 0; - } - - public: - static constexpr size_t OptBufSize = 2 * sizeof(size_t) + sizeof(utf8*) - 1; - using OptBufType = Array; - size_t optLength() const - { - if (optIsLarge()) { - return m_large.optLength; - } - return m_small.optLength; - } - - size_t optCapacity() const - { - if (optIsLarge()) { - return m_large.optCapacity; - } - return OptBufSize - 1U; - } - - private: void setLength(size_t newLength) { m_length = newLength; - if (optIsLarge()) { - m_large.optLength = newLength; - } else { - m_small.optLength = static_cast(newLength); - } } /** \brief The allocator used to get storage for characters when the string * is large. */ Allocator* m_allocator{&globalFudAllocator}; - union { - struct { - size_t optLength; - size_t optCapacity; - utf8* optData; - } m_large; - struct { - uint8_t optLength; - OptBufType optBuffer; - } m_small; - }; - using BufType = Array; union { /** \brief The storage for string characters when using SSO. */ diff --git a/source/fud_string.cpp b/source/fud_string.cpp index 58b6bd1..994689e 100644 --- a/source/fud_string.cpp +++ b/source/fud_string.cpp @@ -100,14 +100,14 @@ StringResult String::from(StringView view, Allocator* allocator) String output{}; output.m_allocator = allocator; - output.m_length = view.m_length; - if (output.m_length >= output.m_capacity) { - output.m_capacity = output.m_length + 1; + if (view.m_length >= output.capacity() + 1U) { + output.m_capacity = view.m_length + 1; output.m_data = static_cast(M_TakeOrReturn(output.allocator()->allocate(output.m_capacity))); fudAssert(output.m_data != nullptr); } + output.setLength(view.m_length); auto copyStatus = copyMem(output.dataMut(), output.m_capacity, view.m_data, output.m_length); fudAssert(copyStatus == FudStatus::Success); -- cgit v1.2.3