From: bert hubert Date: Wed, 23 Jan 2019 20:03:21 +0000 (+0100) Subject: Be smarter about trimming whitespace when creating records from ASCII X-Git-Tag: rec-4.2.0-alpha1~5^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13653a1a39323fd6e360e0ac46296606a81c848a;p=pdns Be smarter about trimming whitespace when creating records from ASCII In ff7ac440afdae4370e12a1b9eb21d4b1389a861f we added trimming of whitespace, so you could turn " 1.2.3.4 " into an A record 0x01020304. This commit made us more flexible but also six times slower in some microbenchmarks. This commit restores the old performance which shaves double digits percentages of time from many benchmarks in 'speedtest', while making "make-a record" six times faster again. --- diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index d227f7369..05661fe80 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -38,7 +38,8 @@ RecordTextReader::RecordTextReader(const string& str, const DNSName& zone) : d_string(str), d_zone(zone), d_pos(0) { /* remove whitespace */ - boost::trim_if(d_string, boost::algorithm::is_space()); + if(!d_string.empty() && ( dns_isspace(*d_string.begin()) || dns_isspace(*d_string.rbegin()) )) + boost::trim_if(d_string, boost::algorithm::is_space()); d_end = d_string.size(); }