2.2.10: merge destroy_string/destroy_binary into destroy_pointer (#5891)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
1 file changed
+8
-19
@@ -845,28 +845,17 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void destroy_string() noexcept
|
template<typename T>
|
||||||
|
static void destroy_pointer(T*& ptr) noexcept
|
||||||
{
|
{
|
||||||
if (string == nullptr)
|
if (ptr == nullptr)
|
||||||
{
|
{
|
||||||
// not initialized (e.g., due to exception in the ctor)
|
// not initialized (e.g., due to exception in the ctor)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AllocatorType<string_t> alloc;
|
AllocatorType<T> alloc;
|
||||||
std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
|
std::allocator_traits<decltype(alloc)>::destroy(alloc, ptr);
|
||||||
std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
|
std::allocator_traits<decltype(alloc)>::deallocate(alloc, ptr, 1);
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_binary() noexcept
|
|
||||||
{
|
|
||||||
if (binary == nullptr)
|
|
||||||
{
|
|
||||||
// not initialized (e.g., due to exception in the ctor)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AllocatorType<binary_t> alloc;
|
|
||||||
std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
|
|
||||||
std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// t must be value_t::array or value_t::object
|
// t must be value_t::array or value_t::object
|
||||||
@@ -1032,11 +1021,11 @@ public:
|
|||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case value_t::string:
|
case value_t::string:
|
||||||
destroy_string();
|
destroy_pointer(string);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case value_t::binary:
|
case value_t::binary:
|
||||||
destroy_binary();
|
destroy_pointer(binary);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case value_t::object:
|
case value_t::object:
|
||||||
|
|||||||
Reference in new issue
Block a user