From 57842ca3d2f33c854a80b2d63ec0fa594b06673b Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Mon, 21 Dec 2009 13:35:24 +0000 Subject: [PATCH] slight speedup of the recursor packetcache (inline comparison function) git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1456 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/recpacketcache.cc | 17 ----------------- pdns/recpacketcache.hh | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/pdns/recpacketcache.cc b/pdns/recpacketcache.cc index b0d0cbbf6..261a7c38a 100644 --- a/pdns/recpacketcache.cc +++ b/pdns/recpacketcache.cc @@ -47,20 +47,3 @@ void RecursorPacketCache::insertResponsePacket(const std::string& responsePacket d_packetCache.insert(e); } - -// needs to take into account: qname, qtype, opcode, rd, qdcount, EDNS size -bool RecursorPacketCache::Entry::operator<(const struct RecursorPacketCache::Entry &rhs) const -{ - const struct dnsheader* - dh=(const struct dnsheader*) d_packet.c_str(), - *rhsdh=(const struct dnsheader*)rhs.d_packet.c_str(); - if(make_tuple(dh->opcode, dh->rd, dh->qdcount) < - make_tuple(rhsdh->opcode, rhsdh->rd, rhsdh->qdcount)) - return true; - - uint16_t qtype, rhsqtype; - string qname=questionExpand(d_packet.c_str(), d_packet.length(), qtype); - string rhsqname=questionExpand(rhs.d_packet.c_str(), rhs.d_packet.length(), rhsqtype); - - return tie(qtype, qname) < tie(rhsqtype, rhsqname); -} diff --git a/pdns/recpacketcache.hh b/pdns/recpacketcache.hh index c3748c8c3..2bfb2c637 100644 --- a/pdns/recpacketcache.hh +++ b/pdns/recpacketcache.hh @@ -3,7 +3,8 @@ #include #include #include - +#include "dns.hh" +#include "namespaces.hh" class RecursorPacketCache { @@ -20,11 +21,36 @@ private: mutable uint32_t d_ttd; mutable std::string d_packet; // "I know what I am doing" - bool operator<(const struct Entry& rhs) const; + inline bool operator<(const struct Entry& rhs) const; }; typedef std::set packetCache_t; packetCache_t d_packetCache; pthread_rwlock_t d_rwlock; }; + +// needs to take into account: qname, qtype, opcode, rd, qdcount, EDNS size +inline bool RecursorPacketCache::Entry::operator<(const struct RecursorPacketCache::Entry &rhs) const +{ + const struct dnsheader* + dh=(const struct dnsheader*) d_packet.c_str(), + *rhsdh=(const struct dnsheader*)rhs.d_packet.c_str(); + if(make_tuple(dh->opcode, dh->rd, dh->qdcount) < + make_tuple(rhsdh->opcode, rhsdh->rd, rhsdh->qdcount)) + return true; + + if((d_packet.size() > 13 && rhs.d_packet.size() > 13) && + (d_packet[12] && rhs.d_packet[12]) && + (d_packet[13] < rhs.d_packet[13])) + return true; + + + uint16_t qtype, rhsqtype; + string qname=questionExpand(d_packet.c_str(), d_packet.length(), qtype); + string rhsqname=questionExpand(rhs.d_packet.c_str(), rhs.d_packet.length(), rhsqtype); + + return tie(qtype, qname) < tie(rhsqtype, rhsqname); +} + + #endif -- 2.49.0