]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Don't do O(n) operation needlessly
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 21 Feb 2019 12:02:04 +0000 (13:02 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 21 Feb 2019 12:02:04 +0000 (13:02 +0100)
pdns/dnsname.hh

index 5533da0f600ef71873a9426deec891d9eac8b8a0..ff64e2097f951d42ffda8223ca0b699c8161317e 100644 (file)
@@ -380,7 +380,6 @@ struct SuffixMatchNode
     {
       d_tree.add(dnsname, true);
       d_nodes.insert(dnsname);
-      updateHuman();
     }
 
     void add(std::vector<std::string> labels)
@@ -392,14 +391,12 @@ struct SuffixMatchNode
         labels.pop_back(); // This is safe because we have a copy of labels
       }
       d_nodes.insert(tmp);
-      updateHuman();
     }
 
     void remove(const DNSName& name)
     {
       d_tree.remove(name);
       d_nodes.erase(name);
-      updateHuman();
     }
 
     void remove(std::vector<std::string> labels)
@@ -411,7 +408,6 @@ struct SuffixMatchNode
         labels.pop_back(); // This is safe because we have a copy of labels
       }
       d_nodes.erase(tmp);
-      updateHuman();
     }
 
     bool check(const DNSName& dnsname) const
@@ -421,25 +417,21 @@ struct SuffixMatchNode
 
     std::string toString() const
     {
-      return d_human;
-    }
-
-  private:
-    mutable std::string d_human;
-    mutable std::set<DNSName> d_nodes; // Only used for string generation
-
-    void updateHuman() {
-      std::string tmp;
+      std::string ret;
       bool first = true;
       for (const auto& n : d_nodes) {
         if (!first) {
-          tmp += ", ";
+          ret += ", ";
         }
         first = false;
-        tmp += n.toString();
+        ret += n.toString();
       }
-      d_human = tmp;
+      return ret;
     }
+
+  private:
+    mutable std::string d_human;
+    mutable std::set<DNSName> d_nodes; // Only used for string generation
 };
 
 std::ostream & operator<<(std::ostream &os, const DNSName& d);