From: Miod Vallat Date: Wed, 25 Jun 2025 17:15:20 +0000 (+0200) Subject: Let toLowerCanonic() invoke toLowerInPlace() instead of duplicating it. X-Git-Tag: rec-5.3.0-alpha2~40^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42ec82c5633e1a622b3ffe8a2bd593322af8a200;p=thirdparty%2Fpdns.git Let toLowerCanonic() invoke toLowerInPlace() instead of duplicating it. Signed-off-by: Miod Vallat --- diff --git a/pdns/misc.hh b/pdns/misc.hh index 710adaa909..eb4ee3afc3 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -307,31 +307,24 @@ inline const string toLower(const string &upper) inline const string toLowerCanonic(const string &upper) { string reply(upper); - if(!upper.empty()) { - unsigned int i, limit= ( unsigned int ) reply.length(); - unsigned char c; - for(i = 0; i < limit ; i++) { - c = dns_tolower(upper[i]); - if(c != upper[i]) - reply[i] = c; + if (!reply.empty()) { + const auto length = reply.length(); + if (reply[length - 1] == '.') { + reply.resize(length - 1); } - if(upper[i-1]=='.') - reply.resize(i-1); + toLowerInPlace(reply); } - return reply; } - - // Make s uppercase: inline string toUpper( const string& s ) { - string r(s); - for( unsigned int i = 0; i < s.length(); i++ ) { - r[i] = dns_toupper(r[i]); - } - return r; + string r(s); + for (size_t i = 0; i < s.length(); ++i) { + r[i] = dns_toupper(r[i]); + } + return r; } inline double getTime()