]> granicus.if.org Git - pdns/commitdiff
replace ugly cache insertion/deleting code by nice alternative from Joaquin Lopez...
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 28 Apr 2006 09:39:49 +0000 (09:39 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 28 Apr 2006 09:39:49 +0000 (09:39 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@785 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/syncres.cc
pdns/syncres.hh

index 6b1d313ce697d1863c919c09b1e1c49cb9308579..157fd69fb4803a0f3daafa54bcaeafa0f71b1686 100644 (file)
@@ -684,11 +684,7 @@ int SyncRes::doResolveAt(set<string, CIStringCompare> nameservers, string auth,
          ne.d_name=qname;
          ne.d_qtype=QType(0);
          
-         pair<negcache_t::iterator, bool> res=s_negcache.insert(ne);
-         if(!res.second) {
-           s_negcache.erase(res.first);
-           s_negcache.insert(ne);
-         }
+         replacing_insert(s_negcache, ne);
          negindic=true;
        }
        else if(i->d_place==DNSResourceRecord::ANSWER && i->qname==qname && i->qtype.getCode()==QType::CNAME && (!(qtype==QType(QType::CNAME)))) {
@@ -727,11 +723,7 @@ int SyncRes::doResolveAt(set<string, CIStringCompare> nameservers, string auth,
          ne.d_name=qname;
          ne.d_qtype=qtype;
          if(qtype.getCode()) {  // prevents us from blacking out a whole domain
-           pair<negcache_t::iterator, bool> res=s_negcache.insert(ne);
-           if(!res.second) {
-             s_negcache.erase(res.first);
-             s_negcache.insert(ne);
-           }
+           replacing_insert(s_negcache, ne);
          }
          negindic=true;
        }
index 926b94b4fc8514223556f38f1f6179c6aaa8daaf..c696d43fca9d684a785a22deb1e640c0b0c9b8ef 100644 (file)
@@ -411,4 +411,15 @@ struct RecursorStats
 };
 
 extern RecursorStats g_stats;
+
+
+template<typename Index>
+std::pair<typename Index::iterator,bool>
+replacing_insert(Index& i,const typename Index::value_type& x)
+{
+  std::pair<typename Index::iterator,bool> res=i.insert(x);
+  if(!res.second)res.second=i.replace(res.first,x);
+  return res;
+}
+
 #endif