From: Bert Hubert Date: Wed, 29 Mar 2006 18:27:22 +0000 (+0000) Subject: 20% speedup or so in xfrLabel by implementing 'vstringtok' which only returns offsets X-Git-Tag: rec-3-0~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c3149f2f1858ba504b17caf67241542c37af8c4;p=pdns 20% speedup or so in xfrLabel by implementing 'vstringtok' which only returns offsets git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@643 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index dbcc33931..b0d099737 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -121,38 +121,38 @@ void DNSPacketWriter::xfrText(const string& text) // this is the absolute hottest function in the pdns recursor void DNSPacketWriter::xfrLabel(const string& label, bool compress) { - typedef vector parts_t; + typedef vector > parts_t; parts_t parts; - stringtok(parts, label, "."); + vstringtok(parts, label, "."); - string enc; // d_stuff is amount of stuff that is yet to be written out - the dnsrecordheader for example unsigned int pos=d_content.size() + d_record.size() + d_stuff; string chopped(label); for(parts_t::const_iterator i=parts.begin(); i!=parts.end(); ++i) { map::iterator li; - if(compress && (li=d_labelmap.find(chopped))!=d_labelmap.end()) { // see if we've written out this domain before + // see if we've written out this domain before + if(compress && (li=d_labelmap.find(chopped))!=d_labelmap.end()) { uint16_t offset=li->second; offset|=0xc000; - enc.append(1, (char)(offset >> 8)); - enc.append(1, (char)(offset & 0xff)); + d_record.push_back((char)(offset >> 8)); + d_record.push_back((char)(offset & 0xff)); goto out; // skip trailing 0 in case of compression } else if(compress || d_labelmap.count(chopped)) { // if 'compress' is true, li will be equal to d_labelmap.end() d_labelmap[chopped]=pos; // if untrue, we need to count } - enc.append(1, (char)i->length()); - enc.append(*i); - pos+=i->length()+1; + d_record.push_back((char)(i->second - i->first)); + unsigned int len=d_record.size(); + d_record.resize(len + i->second - i->first); + memcpy(((&*d_record.begin()) + len), label.c_str() + i-> first, i->second - i->first); + + pos+=(i->second - i->first)+1; chopOff(chopped); // www.powerdns.com -> powerdns.com -> com } - enc.append(1,(char)0); + d_record.push_back(0); out:; - - const uint8_t* ptr=reinterpret_cast(enc.c_str()); - d_record.insert(d_record.end(), ptr, ptr+enc.size()); } void DNSPacketWriter::xfrBlob(const string& blob) diff --git a/pdns/misc.hh b/pdns/misc.hh index 13187eb97..988c901d7 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -115,6 +115,36 @@ stringtok (Container &container, string const &in, i = j + 1; } } + +template +void +vstringtok (Container &container, string const &in, + const char * const delimiters = " \t\n") +{ + const string::size_type len = in.length(); + string::size_type i = 0; + + while (i