From 9772e56de4d79bc6b3418d789ed8ac46119542fc Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Mon, 30 Sep 2019 10:30:25 +0200 Subject: [PATCH] iputils.hh: NetmaskTree: Make tree cleanup mandatory. Potentially leaving branches full of unassigned nodes unnecessarily complicates tree algorithms. Disabling tree cleanup was not used anywhere, except for a unit test. Note that, after this change, individual branch nodes can still be unassigned, but not the whole branch. So, when e.g. the left sub-branch of a node exists, algorithms can rely on the fact that there is at least one assigned node in there. --- pdns/iputils.hh | 20 ++++---------------- pdns/recursor_cache.hh | 2 +- pdns/test-iputils_hh.cc | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/pdns/iputils.hh b/pdns/iputils.hh index ea97030764..9a66e13b84 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -790,13 +790,10 @@ private: } public: - NetmaskTree() noexcept : NetmaskTree(false) { + NetmaskTree() noexcept : d_root(new TreeNode()) { } - NetmaskTree(bool cleanup) noexcept : d_root(new TreeNode()), d_cleanup_tree(cleanup) { - } - - NetmaskTree(const NetmaskTree& rhs): d_root(new TreeNode()), d_cleanup_tree(rhs.d_cleanup_tree) { + NetmaskTree(const NetmaskTree& rhs): d_root(new TreeNode()) { // it is easier to copy the nodes than tree. // also acts as handy compactor for(auto const& node: rhs._nodes) @@ -808,7 +805,6 @@ public: // see above. for(auto const& node: rhs._nodes) insert(node->first).second = node->second; - d_cleanup_tree = rhs.d_cleanup_tree; return *this; } @@ -1031,9 +1027,7 @@ public: _nodes.erase(node->node.get()); node->assigned = false; node->node->second = value_type(); - - if (d_cleanup_tree) - cleanup_tree(node); + cleanup_tree(node); } } @@ -1075,7 +1069,6 @@ public: private: unique_ptr d_root; // _nodes; // nmt(true); + NetmaskTree nmt; BOOST_CHECK(nmt.empty()); BOOST_CHECK_EQUAL(nmt.size(), 0); -- 2.47.2