]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
iputils.hh: NetmaskTree: Copy the tree using tree traversal.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 30 Sep 2019 08:30:25 +0000 (10:30 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 11 Feb 2020 01:49:36 +0000 (02:49 +0100)
Before, it used the internal std::set.

pdns/iputils.hh

index ce938c7b437640bd97a2575f7c8eb3497908b0a5..129fd578dcb405af429eb588a621701216ccad21 100644 (file)
@@ -834,22 +834,31 @@ private:
     }
   }
 
+  void copyTree(const NetmaskTree& rhs)
+  {
+    TreeNode *node;
+
+    node = rhs.d_root.get();
+    if (node != nullptr)
+      node = node->traverse_l();
+    while (node != nullptr) {
+      if (node->assigned)
+        insert(node->node->first).second = node->node->second;
+      node = node->traverse_lnr();
+    }
+  }
+
 public:
   NetmaskTree() noexcept : d_root(new TreeNode()) {
   }
 
   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)
-      insert(node->first).second = node->second;
+    copyTree(rhs);
   }
 
   NetmaskTree& operator=(const NetmaskTree& rhs) {
     clear();
-    // see above.
-    for(auto const& node: rhs._nodes)
-      insert(node->first).second = node->second;
+    copyTree(rhs);
     return *this;
   }