From: JINMEI Tatuya Date: Wed, 7 Mar 2012 00:05:22 +0000 (-0800) Subject: [1603] proposed update to labelsequence: use internal loop, not strncasecmp. X-Git-Tag: trac2351_base~226^2~116^2~121^2~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7eda3c0ee0795ed21cb4fb44ff20f905de1cf800;p=thirdparty%2Fkea.git [1603] proposed update to labelsequence: use internal loop, not strncasecmp. according to benchmark it can improve the renderer performance 17% more. --- diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc index b082c3970e..f3c213358b 100644 --- a/src/lib/dns/labelsequence.cc +++ b/src/lib/dns/labelsequence.cc @@ -53,9 +53,20 @@ LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const { } if (case_sensitive) { return (strncmp(data, other_data, len) == 0); - } else { - return (strncasecmp(data, other_data, len) == 0); } + + // As long as the data was originally validated as (part of) a name, + // label length must never be a capital ascii character, so we can + // simply compare them after converting to lower characters. + for (size_t i = 0; i < len; ++i) { + const unsigned char ch = data[i]; + const unsigned char other_ch = other_data[i]; + if (isc::dns::name::internal::maptolower[ch] != + isc::dns::name::internal::maptolower[other_ch]) { + return (false); + } + } + return (true); } void