]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
all: DNSName reserve memory before converting to string
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Wed, 27 Mar 2019 14:30:19 +0000 (15:30 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Wed, 27 Mar 2019 14:30:19 +0000 (15:30 +0100)
pdns/dnsname.cc

index ecfda97bec5015ae82db6fdcf247afa740f16d1b..58f2d3a54629d39d514fb4fcc0f6d8d71470dcab 100644 (file)
@@ -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