]> granicus.if.org Git - pdns/commitdiff
back out optString for now
authorBert Hubert <bert.hubert@netherlabs.nl>
Wed, 2 Nov 2005 15:22:59 +0000 (15:22 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Wed, 2 Nov 2005 15:22:59 +0000 (15:22 +0000)
special-special case MemRecursorCache::replace for the even more common case where nothing changed except the ttls

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@536 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/recursor_cache.cc
pdns/recursor_cache.hh

index f176051d31924ad73a51162ab64e0cc5f7238c6c..c036a682c8ab3ce3982fd934458bdd4ca4e6d5bb 100644 (file)
@@ -77,7 +77,7 @@ void MemRecursorCache::replace(const string &qname, const QType& qt,  const set<
     dr.d_string=DNSRR2String(*i);
     k=stored.find(dr);
     if(k!=stored.end()) {           // was it there already?
-      //      cerr<<"updating record '"<<qname<<"' -> '"<<i->content<<"'\n";
+      // cerr<<"updating record '"<<qname<<"' -> '"<<i->content<<"'\n";
       k->d_ttd=i->ttl;              // update ttl
       touched.push_back(k);         // note that this record is here to stay
     }
@@ -86,18 +86,19 @@ void MemRecursorCache::replace(const string &qname, const QType& qt,  const set<
       touched.push_back(stored.insert(dr).first);  // same thing
     }
   }
-
-  for(k=stored.begin(); k!=stored.end(); ) {                     // walk over the stored set of records
-    touched_t::const_iterator j;                                
-    for(j=touched.begin(); j!=touched.end() && *j != k ; ++j);   // walk over touched iterators
-    if(j==touched.end()) {                                       // this record was not there
-      //      DNSResourceRecord rr=String2DNSRR(qname, qt,  k->d_string, 0); 
-      //      cerr<<"removing from record '"<<qname<<"' '"<<rr.content<<"'\n";
-      k->d_string.prune();                                      
-      stored.erase(k++);                                         // cleanup
+  if(touched.size() != stored.size()) {
+    for(k=stored.begin(); k!=stored.end(); ) {                     // walk over the stored set of records
+      touched_t::const_iterator j;                                
+      for(j=touched.begin(); j!=touched.end() && *j != k ; ++j);   // walk over touched iterators
+      if(j==touched.end()) {                                       // this record was not there
+       //      DNSResourceRecord rr=String2DNSRR(qname, qt,  k->d_string, 0); 
+       //      cerr<<"removing from record '"<<qname<<"' '"<<rr.content<<"'\n";
+       //      k->d_string.prune();                                      
+       stored.erase(k++);                                         // cleanup
+      }
+      else
+       ++k;
     }
-    else
-      ++k;
   }
 }
   
@@ -108,7 +109,7 @@ void MemRecursorCache::doPrune(void)
   for(cache_t::iterator j=d_cache.begin();j!=d_cache.end();){
     for(set<StoredRecord>::iterator k=j->second.begin();k!=j->second.end();) 
       if((unsigned int)k->d_ttd < (unsigned int) now) {
-       k->d_string.prune();
+       //      k->d_string.prune();
        j->second.erase(k++);
        records++;
       }
index 9ad8385ed50e692a07dcd7043327b820856fcfc4..5cb8070fd6844ba9052c43cdccd683e113439aa2 100644 (file)
@@ -6,6 +6,7 @@
 #include "dns.hh"
 #include "qtype.hh"
 #include <iostream>
+#include <boost/utility.hpp>
 
 template<int N=14>
 struct optString
@@ -16,6 +17,11 @@ struct optString
     *buf=0;
   }
 
+  optString(const optString& rhs) : d_len(rhs.d_len)
+  {
+    memcpy(buf, rhs.buf, N);
+  }
+
   optString(const string& str)
   {
     if(str.size() < N-1) {
@@ -56,12 +62,9 @@ struct optString
 } __attribute__((packed));
 
 
-
-
-class MemRecursorCache //  : public RecursorCache
+class MemRecursorCache : public boost::noncopyable //  : public RecursorCache
 {
 public:
-  ~MemRecursorCache(){}
   unsigned int size();
   int get(time_t, const string &qname, const QType& qt, set<DNSResourceRecord>* res);
   void replace(const string &qname, const QType& qt,  const set<DNSResourceRecord>& content);
@@ -72,7 +75,8 @@ private:
   struct StoredRecord
   {
     mutable uint32_t d_ttd;
-    optString<> d_string;
+    //    optString<> d_string;
+    string d_string;
     bool operator<(const StoredRecord& rhs) const
     {
       return d_string < rhs.d_string;