Parcourir la source

bug #1749: Address review comments (from bug #1748)

Mukund Sivaraman il y a 13 ans
Parent
commit
ac2c63f07c
2 fichiers modifiés avec 14 ajouts et 11 suppressions
  1. 12 9
      src/lib/datasrc/rbnode_rrset.h
  2. 2 2
      src/lib/datasrc/tests/rbnode_rrset_unittest.cc

+ 12 - 9
src/lib/datasrc/rbnode_rrset.h

@@ -127,15 +127,18 @@ public:
 
     virtual std::string toText() const;
 
-    virtual bool isSameKind(const AbstractRRset& other) {
-        const AbstractRRset* t = &other;
-        const RBNodeRRset* rb;
-
-        rb = dynamic_cast<const RBNodeRRset*>(t);
-        if (rb)
-          return (this == rb);
-        else
-          return AbstractRRset::isSameKind(other);
+    virtual bool isSameKind(const AbstractRRset& other) const {
+        // This code is an optimisation for comparing
+        // RBNodeRRsets. However, in doing this optimisation,
+        // semantically the code is not "is same kind" but is instead
+        // "is identical object" in the case where RBNodeRRsets are compared.
+
+        const RBNodeRRset* rb = dynamic_cast<const RBNodeRRset*>(&other);
+        if (rb != NULL) {
+            return (this == rb);
+        } else {
+            return (AbstractRRset::isSameKind(other));
+        }
     }
 
     virtual unsigned int toWire(

+ 2 - 2
src/lib/datasrc/tests/rbnode_rrset_unittest.cc

@@ -142,7 +142,7 @@ TEST_F(RBNodeRRsetTest, isSameKind) {
     RBNodeRRset rrset_p(ConstRRsetPtr(new RRset(test_name, RRClass::IN(), RRType::A(), RRTTL(3600))));
     RBNodeRRset rrset_q(ConstRRsetPtr(new RRset(test_name, RRClass::IN(), RRType::A(), RRTTL(3600))));
     RRset rrset_w(test_name, RRClass::IN(), RRType::A(), RRTTL(3600));
-    RRset rrset_x(test_name, RRClass::IN(), RRType::A(), RRTTL(3600));
+    RRset rrset_x(test_nsname, RRClass::IN(), RRType::A(), RRTTL(3600));
     RRset rrset_y(test_name, RRClass::IN(), RRType::NS(), RRTTL(3600));
     RRset rrset_z(test_name, RRClass::CH(), RRType::A(), RRTTL(3600));
 
@@ -150,7 +150,7 @@ TEST_F(RBNodeRRsetTest, isSameKind) {
     EXPECT_FALSE(rrset_p.isSameKind(rrset_q));
 
     EXPECT_TRUE(rrset_p.isSameKind(rrset_w));
-    EXPECT_TRUE(rrset_p.isSameKind(rrset_x));
+    EXPECT_FALSE(rrset_p.isSameKind(rrset_x));
     EXPECT_FALSE(rrset_p.isSameKind(rrset_y));
     EXPECT_FALSE(rrset_p.isSameKind(rrset_z));
 }