From b0e3bd8541fe10b8bee4e63680fbc2fa5f373164 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 4 Nov 2019 23:49:20 +0100 Subject: [PATCH] [rtree] Simplify node destruction calls. --- .../boost/geometry/index/detail/rtree/node/node.hpp | 11 +++++++---- .../index/detail/rtree/node/subtree_destroyer.hpp | 3 +-- .../boost/geometry/index/detail/rtree/pack_create.hpp | 1 + .../geometry/index/detail/rtree/rstar/insert.hpp | 3 +-- .../geometry/index/detail/rtree/visitors/copy.hpp | 2 ++ .../geometry/index/detail/rtree/visitors/destroy.hpp | 10 ++++++++-- .../geometry/index/detail/rtree/visitors/insert.hpp | 5 +++-- .../geometry/index/detail/rtree/visitors/remove.hpp | 6 +++--- include/boost/geometry/index/rtree.hpp | 7 +++---- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/boost/geometry/index/detail/rtree/node/node.hpp b/include/boost/geometry/index/detail/rtree/node/node.hpp index e4db82d2c..ad3e24c15 100644 --- a/include/boost/geometry/index/detail/rtree/node/node.hpp +++ b/include/boost/geometry/index/detail/rtree/node/node.hpp @@ -31,10 +31,9 @@ #include #include -#include - #include +#include #include #include @@ -114,7 +113,8 @@ struct destroy_element inline static void apply(typename internal_node::elements_type::value_type & element, allocators_type & allocators) { - rtree::subtree_destroyer dummy(element.second, allocators); + detail::rtree::visitors::destroy::apply(element.second, allocators); + element.second = 0; } @@ -155,7 +155,8 @@ private: { for ( ; first != last ; ++first ) { - rtree::subtree_destroyer dummy(first->second, allocators); + detail::rtree::visitors::destroy::apply(first->second, allocators); + first->second = 0; } } @@ -167,6 +168,7 @@ private: }; // clears node, deletes all subtrees stored in node +/* template struct clear_node { @@ -202,6 +204,7 @@ struct clear_node rtree::elements(leaf).clear(); } }; +*/ template void move_from_back(Container & container, Iterator it) diff --git a/include/boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp b/include/boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp index ca65bad32..838d757ab 100644 --- a/include/boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp +++ b/include/boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp @@ -47,8 +47,7 @@ public: { if ( m_ptr && m_ptr != ptr ) { - detail::rtree::visitors::destroy del_v(m_ptr, m_allocators); - detail::rtree::apply_visitor(del_v, *m_ptr); + detail::rtree::visitors::destroy::apply(m_ptr, m_allocators); } m_ptr = ptr; } diff --git a/include/boost/geometry/index/detail/rtree/pack_create.hpp b/include/boost/geometry/index/detail/rtree/pack_create.hpp index 7280c3000..52a3846fb 100644 --- a/include/boost/geometry/index/detail/rtree/pack_create.hpp +++ b/include/boost/geometry/index/detail/rtree/pack_create.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include diff --git a/include/boost/geometry/index/detail/rtree/rstar/insert.hpp b/include/boost/geometry/index/detail/rtree/rstar/insert.hpp index 8a9cb7166..e11636f0f 100644 --- a/include/boost/geometry/index/detail/rtree/rstar/insert.hpp +++ b/include/boost/geometry/index/detail/rtree/rstar/insert.hpp @@ -394,8 +394,7 @@ struct level_insert // NOTE: exception-safety // if the insert fails above, the element won't be stored in the tree, so delete it - rtree::visitors::destroy del_v(base::m_element.second, base::m_allocators); - rtree::apply_visitor(del_v, *base::m_element.second); + rtree::visitors::destroy::apply(base::m_element.second, base::m_allocators); BOOST_RETHROW // RETHROW } diff --git a/include/boost/geometry/index/detail/rtree/visitors/copy.hpp b/include/boost/geometry/index/detail/rtree/visitors/copy.hpp index 1c3229b07..1dee43d63 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/copy.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/copy.hpp @@ -15,6 +15,8 @@ #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP +#include + namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { diff --git a/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp b/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp index fd4315d42..4afb867cd 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/destroy.hpp @@ -31,8 +31,8 @@ public: typedef typename MembersHolder::allocators_type allocators_type; typedef typename MembersHolder::node_pointer node_pointer; - inline destroy(node_pointer root_node, allocators_type & allocators) - : m_current_node(root_node) + inline destroy(node_pointer node, allocators_type & allocators) + : m_current_node(node) , m_allocators(allocators) {} @@ -64,6 +64,12 @@ public: rtree::destroy_node::apply(m_allocators, m_current_node); } + static inline void apply(node_pointer node, allocators_type & allocators) + { + destroy v(node, allocators); + rtree::apply_visitor(v, *node); + } + private: node_pointer m_current_node; allocators_type & m_allocators; diff --git a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp index 1e9823782..490f66feb 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/insert.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/insert.hpp @@ -23,6 +23,8 @@ #include #include +#include + namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { @@ -533,8 +535,7 @@ public: { // if the insert fails above, the element won't be stored in the tree - rtree::visitors::destroy del_v(base::m_element.second, base::m_allocators); - rtree::apply_visitor(del_v, *base::m_element.second); + rtree::visitors::destroy::apply(base::m_element.second, base::m_allocators); BOOST_RETHROW // RETHROW } diff --git a/include/boost/geometry/index/detail/rtree/visitors/remove.hpp b/include/boost/geometry/index/detail/rtree/visitors/remove.hpp index efb7c0725..59f486163 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/remove.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/remove.hpp @@ -15,6 +15,7 @@ #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_REMOVE_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_REMOVE_HPP +#include #include #include @@ -283,7 +284,7 @@ private: // destroy current and remaining nodes for ( ; it != m_underflowed_nodes.rend() ; ++it ) { - subtree_destroyer dummy(it->second, m_allocators); + rtree::visitors::destroy::apply(it->second, m_allocators); } //m_underflowed_nodes.clear(); @@ -315,8 +316,7 @@ private: BOOST_CATCH(...) { ++it; - rtree::destroy_elements - ::apply(it, elements.end(), m_allocators); + rtree::destroy_elements::apply(it, elements.end(), m_allocators); elements.clear(); BOOST_RETHROW // RETHROW } diff --git a/include/boost/geometry/index/rtree.hpp b/include/boost/geometry/index/rtree.hpp index c445abd36..dcc647d2c 100644 --- a/include/boost/geometry/index/rtree.hpp +++ b/include/boost/geometry/index/rtree.hpp @@ -1639,8 +1639,7 @@ private: if ( t.m_members.root ) { detail::rtree::visitors::destroy - del_v(t.m_members.root, t.m_members.allocators()); - detail::rtree::apply_visitor(del_v, *t.m_members.root); + ::apply(t.m_members.root, t.m_members.allocators()); t.m_members.root = 0; } @@ -1677,8 +1676,8 @@ private: if ( dst.m_members.root ) { detail::rtree::visitors::destroy - del_v(dst.m_members.root, dst.m_members.allocators()); - detail::rtree::apply_visitor(del_v, *dst.m_members.root); + ::apply(dst.m_members.root, dst.m_members.allocators()); + dst.m_members.root = 0; }