From: Pieter Lexis Date: Thu, 21 Feb 2019 12:02:04 +0000 (+0100) Subject: Don't do O(n) operation needlessly X-Git-Tag: rec-4.2.0-beta1~7^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5115d1e74eb9aaa02683e599ce36ab365e8ce9;p=thirdparty%2Fpdns.git Don't do O(n) operation needlessly --- diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 5533da0f60..ff64e2097f 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -380,7 +380,6 @@ struct SuffixMatchNode { d_tree.add(dnsname, true); d_nodes.insert(dnsname); - updateHuman(); } void add(std::vector 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 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 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 d_nodes; // Only used for string generation }; std::ostream & operator<<(std::ostream &os, const DNSName& d);