From: Charles-Henri Bruyand Date: Wed, 27 Mar 2019 14:30:19 +0000 (+0100) Subject: all: DNSName reserve memory before converting to string X-Git-Tag: dnsdist-1.4.0-rc1~126^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0da87e09e98c1c9249e06cd22bb0d0451bba7ee;p=thirdparty%2Fpdns.git all: DNSName reserve memory before converting to string --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index ecfda97bec..58f2d3a546 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -165,15 +165,18 @@ std::string DNSName::toString(const std::string& separator, const bool trailing) throw std::out_of_range("Attempt to print an unset dnsname"); } - if(isRoot()) + if(isRoot()) return trailing ? separator : ""; std::string ret; + ret.reserve(d_storage.size()); for(const auto& s : getRawLabels()) { ret+= escapeLabel(s) + separator; } - - return ret.substr(0, ret.size()-!trailing); + if (!trailing) { + ret.resize(ret.size() - separator.size()); + } + return ret; } std::string DNSName::toLogString() const