From 49bd5a203ffda87ef731fe68c8db47c7dc0db10f Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Fri, 11 Nov 2005 12:45:31 +0000 Subject: [PATCH] big speedup in endsOn git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@545 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/misc.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pdns/misc.cc b/pdns/misc.cc index 75153ee932..d3cab3fc1d 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -106,16 +106,36 @@ bool chopOff(string &domain) return true; } +bool ciEqual(const string& a, const string& b) +{ + if(a.size()!=b.size()) + return false; + + string::size_type pos=0, epos=a.size(); + for(;pos < epos; ++pos) + if(dns_tolower(a[pos])!=dns_tolower(b[pos])) + return false; + return true; +} + /** does domain end on suffix? Is smart about "wwwds9a.nl" "ds9a.nl" not matching */ bool endsOn(const string &domain, const string &suffix) { - if(toLower(domain)==toLower(suffix) || suffix.empty()) + if( suffix.empty() || ciEqual(domain, suffix) ) return true; if(domain.size()<=suffix.size()) return false; - return (toLower(domain.substr(domain.size()-suffix.size()-1,suffix.size()+1))=="."+toLower(suffix)); -} + + string::size_type dpos=domain.size()-suffix.size()-1, spos=0; + if(domain[dpos++]!='.') + return false; + for(; dpos < domain.size(); ++dpos, ++spos) + if(dns_tolower(domain[dpos]) != dns_tolower(suffix[spos])) + return false; + + return true; +} int sendData(const char *buffer, int replen, int outsock) { @@ -136,7 +156,6 @@ int sendData(const char *buffer, int replen, int outsock) return 0; } - void parseService(const string &descr, ServiceTuple &st) { -- 2.47.3