From cb49908fe903bcfa2dee1ed5969425f302fcdc53 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 27 Sep 2019 16:09:11 -0700 Subject: [PATCH] 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. --- include/boost/json/impl/object.hpp | 3 +++ include/boost/json/impl/storage.ipp | 14 -------------- include/boost/json/storage.hpp | 15 +++++++++++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/boost/json/impl/object.hpp b/include/boost/json/impl/object.hpp index a2d02ffc..d341a26f 100644 --- a/include/boost/json/impl/object.hpp +++ b/include/boost/json/impl/object.hpp @@ -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(p); } diff --git a/include/boost/json/impl/storage.ipp b/include/boost/json/impl/storage.ipp index 5ed74b4e..637e0bfe 100644 --- a/include/boost/json/impl/storage.ipp +++ b/include/boost/json/impl/storage.ipp @@ -12,26 +12,12 @@ #include #include -#include #include #include 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_) diff --git a/include/boost/json/storage.hpp b/include/boost/json/storage.hpp index 0523c439..fc5de171 100644 --- a/include/boost/json/storage.hpp +++ b/include/boost/json/storage.hpp @@ -11,6 +11,7 @@ #define BOOST_JSON_STORAGE_HPP #include +#include #include #include #include @@ -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;