[svn] commit: r2033 - in /branches/trac192/src/lib/datasrc: cache.cc cache.h data_source.cc tests/cache_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jun 2 01:59:45 UTC 2010


Author: jinmei
Date: Wed Jun  2 01:59:45 2010
New Revision: 2033

Log:
(possibly less trivial) cleanup:
introduce "ConstCacheNodePtr" instead of "const CacheNodePtr", and use
it whenever possible.  "const shared_ptr" is almost always different
from what was actually intended, and I believe that's the case here,
too.  ("const shared_ptr X" is an equivalent of "type* const X", not
"const type* X", and when we say "const shared_ptr X", the intent is normally
the latter).

Modified:
    branches/trac192/src/lib/datasrc/cache.cc
    branches/trac192/src/lib/datasrc/cache.h
    branches/trac192/src/lib/datasrc/data_source.cc
    branches/trac192/src/lib/datasrc/tests/cache_unittest.cc

Modified: branches/trac192/src/lib/datasrc/cache.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/cache.cc (original)
+++ branches/trac192/src/lib/datasrc/cache.cc Wed Jun  2 01:59:45 2010
@@ -85,7 +85,7 @@
 }
 
 
-CacheNodePtr
+ConstCacheNodePtr
 HotCache::retrieve(Name n, RRClass c, RRType t) {
     CacheNodePtr node = map_[QTuple(n, c, t)];
     if (! node) {
@@ -123,14 +123,13 @@
 
 void
 HotCache::cache(RRsetPtr rrset, const uint32_t flags, const time_t interval) {
-    CacheNodePtr node = retrieve(rrset->getName(), rrset->getClass(), 
-                                 rrset->getType());
+    ConstCacheNodePtr node = retrieve(rrset->getName(), rrset->getClass(), 
+                                      rrset->getType());
     if (node) {
         remove(node);
     }
 
-    node = CacheNodePtr(new CacheNode(rrset, flags, interval));
-    insert(node);
+    insert(CacheNodePtr(new CacheNode(rrset, flags, interval)));
 }
 
 void
@@ -142,13 +141,12 @@
         return;
     }
 
-    CacheNodePtr node = retrieve(name, rrclass, rrtype);
+    ConstCacheNodePtr node = retrieve(name, rrclass, rrtype);
     if (node) {
         remove(node);
     }
 
-    node = CacheNodePtr(new CacheNode(name, rrclass, rrtype, flags, interval));
-    insert(node);
+    insert(CacheNodePtr(new CacheNode(name, rrclass, rrtype, flags, interval)));
 }
 
 void
@@ -198,7 +196,7 @@
 }
 
 void
-HotCache::remove(CacheNodePtr node) {
+HotCache::remove(ConstCacheNodePtr node) {
     if (!node) {
         return;
     }

Modified: branches/trac192/src/lib/datasrc/cache.h
==============================================================================
--- branches/trac192/src/lib/datasrc/cache.h (original)
+++ branches/trac192/src/lib/datasrc/cache.h Wed Jun  2 01:59:45 2010
@@ -33,6 +33,7 @@
 
 class CacheNode;
 typedef boost::shared_ptr<CacheNode> CacheNodePtr;
+typedef boost::shared_ptr<const CacheNode> ConstCacheNodePtr;
 class CacheEntry;
 typedef boost::shared_ptr<CacheEntry> CacheEntryPtr;
 
@@ -216,9 +217,9 @@
     /// \param rrtype The query type
     ///
     /// \return \c CacheNodePtr, empty if no data was found in the cache.
-    CacheNodePtr retrieve(isc::dns::Name qname,
-                          isc::dns::RRClass qclass,
-                          isc::dns::RRType qtype);
+    ConstCacheNodePtr retrieve(isc::dns::Name qname,
+                               isc::dns::RRClass qclass,
+                               isc::dns::RRType qtype);
     //@}
 
 
@@ -259,10 +260,10 @@
     void promote(CacheNodePtr node);
 
     // Remove a node from the cache.
-    void remove(CacheNodePtr node);
+    void remove(ConstCacheNodePtr node);
 
     // Insert a node into the cache (called by both cache() and ncache())
-    inline void insert(const CacheNodePtr node);
+    inline void insert(CacheNodePtr node);
 };
 
 

Modified: branches/trac192/src/lib/datasrc/data_source.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/data_source.cc (original)
+++ branches/trac192/src/lib/datasrc/data_source.cc Wed Jun  2 01:59:45 2010
@@ -144,7 +144,7 @@
     HotCache& cache = task.q.cache;
     RRsetList rrsets;
     RRsetPtr rrset;
-    CacheNodePtr cnode;
+    ConstCacheNodePtr cnode;
     int count = 0;
     uint32_t flags = 0;
     bool found = false;
@@ -188,8 +188,9 @@
 
         cnode = cache.retrieve(task.qname, task.qclass, task.qtype);
         if (!cnode || !cnode->getRRset() != 0) {
-            CacheNodePtr cnamenode = cache.retrieve(task.qname, task.qclass,
-                                                    RRType::CNAME());
+            ConstCacheNodePtr cnamenode = cache.retrieve(task.qname,
+                                                         task.qclass,
+                                                         RRType::CNAME());
             if (cnamenode && cnamenode->getRRset()) {
                 cnode = cnamenode;
             }

Modified: branches/trac192/src/lib/datasrc/tests/cache_unittest.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/cache_unittest.cc (original)
+++ branches/trac192/src/lib/datasrc/tests/cache_unittest.cc Wed Jun  2 01:59:45 2010
@@ -133,7 +133,7 @@
 };
 
 TEST_F(CacheTest, flags) {
-    CacheNodePtr c;
+    ConstCacheNodePtr c;
     c = cache.retrieve(test_name, RRClass::IN(), RRType::A());
     EXPECT_TRUE(c);
     EXPECT_TRUE(c->getRRset());
@@ -152,7 +152,7 @@
 
 TEST_F(CacheTest, retrieveFail)
 {
-    CacheNodePtr c;
+    ConstCacheNodePtr c;
 
     c = cache.retrieve(Name("fake"), RRClass::IN(), RRType::A());
     EXPECT_FALSE(c);
@@ -176,8 +176,8 @@
     cache.cache(aaaa, 0, (time_t) 2);
 
     sleep(3);
-    CacheNodePtr c = cache.retrieve(Name("foo"), RRClass::IN(),
-                                RRType::AAAA());
+    ConstCacheNodePtr c = cache.retrieve(Name("foo"), RRClass::IN(),
+                                         RRType::AAAA());
     EXPECT_FALSE(c);
 };
 
@@ -214,7 +214,7 @@
     cache.cache(four, 0, (time_t) 30);
     EXPECT_EQ(5, cache.getCount());
 
-    CacheNodePtr c = cache.retrieve(test_name, RRClass::IN(), RRType::A());
+    ConstCacheNodePtr c = cache.retrieve(test_name, RRClass::IN(), RRType::A());
     EXPECT_FALSE(c);
 
     c = cache.retrieve(test_ch, RRClass::CH(), RRType::TXT());
@@ -225,7 +225,8 @@
 {
     Name missing("missing.example.com");
     cache.ncache(missing, RRClass::IN(), RRType::DNSKEY(), 8, 30);
-    CacheNodePtr c = cache.retrieve(missing, RRClass::IN(), RRType::DNSKEY());
+    ConstCacheNodePtr c = cache.retrieve(missing, RRClass::IN(),
+                                         RRType::DNSKEY());
     EXPECT_TRUE(c);
     EXPECT_FALSE(c->getRRset());
     EXPECT_EQ(8, c->getFlags());
@@ -240,7 +241,7 @@
 
     EXPECT_NO_THROW(cache.cache(a, 16, 30));
     EXPECT_EQ(3, cache.getCount());
-    CacheNodePtr c = cache.retrieve(test_name, RRClass::IN(), RRType::A());
+    ConstCacheNodePtr c = cache.retrieve(test_name, RRClass::IN(), RRType::A());
     EXPECT_TRUE(c);
     EXPECT_TRUE(c->getRRset());
     EXPECT_EQ(16, c->getFlags());




More information about the bind10-changes mailing list