Skip to content

Commit

Permalink
Improve basic_json storage
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Oct 25, 2024
1 parent f8f5e6e commit a4ede92
Showing 1 changed file with 16 additions and 37 deletions.
53 changes: 16 additions & 37 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,6 @@ namespace jsoncons {
return *this;
}

~long_string_storage() noexcept
{
heap_string_factory_type::destroy(ptr_);
}

void swap(long_string_storage& other) noexcept
{
using std::swap;
Expand Down Expand Up @@ -832,11 +827,6 @@ namespace jsoncons {
return *this;
}

~byte_string_storage() noexcept
{
heap_string_factory_type::destroy(ptr_);
}

void swap(byte_string_storage& other) noexcept
{
using std::swap;
Expand Down Expand Up @@ -882,7 +872,6 @@ namespace jsoncons {
uint8_t storage_kind_:4;
uint8_t short_str_length_:4;
semantic_tag tag_;

pointer ptr_;

template <typename... Args>
Expand Down Expand Up @@ -962,14 +951,6 @@ namespace jsoncons {
}
}

~array_storage() noexcept
{
if (ptr_ != nullptr)
{
destroy();
}
}

void assign(const array_storage& other)
{
tag_ = other.tag_;
Expand Down Expand Up @@ -1099,14 +1080,6 @@ namespace jsoncons {
}
}

~object_storage() noexcept
{
if (ptr_ != nullptr)
{
destroy();
}
}

void assign(const object_storage& other)
{
tag_ = other.tag_;
Expand Down Expand Up @@ -1852,17 +1825,29 @@ namespace jsoncons {
switch (storage_kind())
{
case json_storage_kind::long_str:
destroy_var<long_string_storage>();
{
long_string_storage::heap_string_factory_type::destroy(cast<long_string_storage>().ptr_);
break;
}
case json_storage_kind::byte_str:
destroy_var<byte_string_storage>();
byte_string_storage::heap_string_factory_type::destroy(cast<byte_string_storage>().ptr_);
break;
case json_storage_kind::array:
destroy_var<array_storage>();
{
auto& storage = cast<array_storage>();
typename array_storage::array_allocator alloc{storage.ptr_->get_allocator()};
std::allocator_traits<array_storage::array_allocator>::destroy(alloc, extension_traits::to_plain_pointer(storage.ptr_));
std::allocator_traits<array_storage::array_allocator>::deallocate(alloc, storage.ptr_,1);
break;
}
case json_storage_kind::object:
destroy_var<object_storage>();
{
auto& storage = cast<object_storage>();
typename object_storage::object_allocator alloc{storage.ptr_->get_allocator()};
std::allocator_traits<object_storage::object_allocator>::destroy(alloc, extension_traits::to_plain_pointer(storage.ptr_));
std::allocator_traits<object_storage::object_allocator>::deallocate(alloc, storage.ptr_,1);
break;
}
default:
break;
}
Expand All @@ -1874,12 +1859,6 @@ namespace jsoncons {
::new (&cast<VariantType>()) VariantType(std::forward<Args>(args)...);
}

template <typename T>
void destroy_var()
{
cast<T>().~T();
}

template <typename T>
struct identity { using type = T*; };
public:
Expand Down

0 comments on commit a4ede92

Please sign in to comment.