2
0
mirror of https://github.com/boostorg/json.git synced 2026-02-15 13:12:17 +00:00

Move some storage_ptr definitions:

The destructor and move constructor definitions are moved
to the header file to allow the compiler to still optimize
some array and object operations when whole program
optimization is not turned on.
This commit is contained in:
Vinnie Falco
2019-09-27 16:09:11 -07:00
parent ec197d4bce
commit cb49908fe9
3 changed files with 14 additions and 18 deletions

View File

@@ -80,8 +80,11 @@ struct object::element
p[sizeof(element) +
n + key.size()] = '\0';
boost::ignore_unused(e);
#if 0
// VFALCO This causes unnecessary addref/release
BOOST_ASSERT(
*e->v_.get_storage() == *sp);
#endif
return reinterpret_cast<element*>(p);
}

View File

@@ -12,26 +12,12 @@
#include <boost/json/storage.hpp>
#include <boost/json/detail/storage_adaptor.hpp>
#include <boost/core/exchange.hpp>
#include <boost/assert.hpp>
#include <memory>
namespace boost {
namespace json {
storage_ptr::
~storage_ptr()
{
if(p_)
p_->release();
}
storage_ptr::
storage_ptr(storage_ptr&& other) noexcept
: p_(boost::exchange(other.p_, nullptr))
{
}
storage_ptr::
storage_ptr(storage_ptr const& other) noexcept
: p_(other.p_)

View File

@@ -11,6 +11,7 @@
#define BOOST_JSON_STORAGE_HPP
#include <boost/json/detail/config.hpp>
#include <boost/core/exchange.hpp>
#include <cstddef>
#include <cstdlib>
#include <type_traits>
@@ -86,11 +87,17 @@ class storage_ptr
public:
storage_ptr() = default;
BOOST_JSON_DECL
~storage_ptr();
~storage_ptr()
{
if(p_)
p_->release();
}
BOOST_JSON_DECL
storage_ptr(storage_ptr&&) noexcept;
storage_ptr(storage_ptr&& other) noexcept
: p_(boost::exchange(
other.p_, nullptr))
{
}
BOOST_JSON_DECL
storage_ptr(storage_ptr const&) noexcept;