From: Stephan Bosch Date: Mon, 30 Sep 2019 08:30:25 +0000 (+0200) Subject: iputils.hh: NetmaskTree: Make tree cleanup mandatory. X-Git-Tag: auth-4.3.0-beta2~20^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9772e56de4d79bc6b3418d789ed8ac46119542fc;p=thirdparty%2Fpdns.git 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. --- 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);