From 739f62788d24ab64023b736532c610eae6891c4d Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Fri, 28 Apr 2006 09:39:49 +0000 Subject: [PATCH] replace ugly cache insertion/deleting code by nice alternative from Joaquin Lopez Munoz git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@785 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/syncres.cc | 12 ++---------- pdns/syncres.hh | 11 +++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 6b1d313ce..157fd69fb 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -684,11 +684,7 @@ int SyncRes::doResolveAt(set nameservers, string auth, ne.d_name=qname; ne.d_qtype=QType(0); - pair 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 nameservers, string auth, ne.d_name=qname; ne.d_qtype=qtype; if(qtype.getCode()) { // prevents us from blacking out a whole domain - pair res=s_negcache.insert(ne); - if(!res.second) { - s_negcache.erase(res.first); - s_negcache.insert(ne); - } + replacing_insert(s_negcache, ne); } negindic=true; } diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 926b94b4f..c696d43fc 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -411,4 +411,15 @@ struct RecursorStats }; extern RecursorStats g_stats; + + +template +std::pair +replacing_insert(Index& i,const typename Index::value_type& x) +{ + std::pair res=i.insert(x); + if(!res.second)res.second=i.replace(res.first,x); + return res; +} + #endif -- 2.49.0