Browse Source

[2098] use a real name object for real name instead of serialized labelseqs

It will simplify various parts of the code.
Name object is expensive, but either way it involves memory allocation
anyway, so performance impact wouldn't be much different.
JINMEI Tatuya 12 years ago
parent
commit
a92987802f
2 changed files with 26 additions and 52 deletions
  1. 16 41
      src/lib/datasrc/memory/treenode_rrset.cc
  2. 10 11
      src/lib/datasrc/memory/treenode_rrset.h

+ 16 - 41
src/lib/datasrc/memory/treenode_rrset.cc

@@ -40,22 +40,11 @@ namespace isc {
 namespace datasrc {
 namespace memory {
 
-TreeNodeRRset::TreeNodeRRset(const dns::Name& realname,
-                             const dns::RRClass& rrclass,
-                             const ZoneNode* node, const RdataSet* rdataset,
-                             bool dnssec_ok) :
-    node_(node), rdataset_(rdataset),
-    rrsig_count_(rdataset_->getSigRdataCount()), rrclass_(rrclass),
-    dnssec_ok_(dnssec_ok), name_(NULL)
-{
-    const LabelSequence labels(realname);
-    const size_t labels_storangelen = labels.getSerializedLength();
-    realname_buf_ = new uint8_t[labels_storangelen];
-    labels.serialize(realname_buf_, labels_storangelen);
-}
-
 const Name&
 TreeNodeRRset::getName() const {
+    if (realname_ != NULL) {
+        return (*realname_);
+    }
     if (name_ == NULL) {
         uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
         const LabelSequence name_labels = getOwnerLabels(labels_buf);
@@ -342,38 +331,24 @@ TreeNodeRRset::isSameKind(const AbstractRRset& abs_other) const {
         // Same for the owner name.  Comparing the nodes also detect
         // the case where RR classes are different (see the method description
         // of the header for details).
-        // hasSameRealName() is a bit more complicated and we expect the
-        // two nodes are often different here in practice, so we check that
-        // condition first.
-        if (node_ != other->node_ || !hasSameRealName(*other)) {
+        if (node_ != other->node_ ) {
             return (false);
         }
-        return (true);
-    }
-    return (AbstractRRset::isSameKind(abs_other));
-}
-
-bool
-TreeNodeRRset::hasSameRealName(const TreeNodeRRset& other) const {
-    // If one is constructed with a "real name" and the other isn't
-    // *we consider* them different.
-    if ((realname_buf_ == NULL && other.realname_buf_ != NULL) ||
-        (realname_buf_ != NULL && other.realname_buf_ == NULL)) {
-        return (false);
-    }
-
-    // If both are constructed with a "real name", we compare their names
-    // (as label sequences) explicitly.
-    if (realname_buf_ != NULL && other.realname_buf_ != NULL) {
-        uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
-        uint8_t other_labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH];
-        if (!getOwnerLabels(labels_buf).equals(
-                other.getOwnerLabels(other_labels_buf))) {
+        // If one is constructed with a "real name" and the other isn't
+        // *we consider* them different.
+        if ((realname_ == NULL && other->realname_ != NULL) ||
+            (realname_ != NULL && other->realname_ == NULL)) {
             return (false);
         }
+        // If both are constructed with a "real name", we compare their names
+        // (as label sequences) explicitly.
+        if (realname_ != NULL && other->realname_ != NULL &&
+            realname_->nequals(*other->realname_)) {
+            return (false);
+        }
+        return (true);
     }
-
-    return (true);
+    return (AbstractRRset::isSameKind(abs_other));
 }
 
 } // namespace memory

+ 10 - 11
src/lib/datasrc/memory/treenode_rrset.h

@@ -105,7 +105,7 @@ public:
                   const RdataSet* rdataset, bool dnssec_ok) :
         node_(node), rdataset_(rdataset),
         rrsig_count_(rdataset_->getSigRdataCount()), rrclass_(rrclass),
-        dnssec_ok_(dnssec_ok), name_(NULL), realname_buf_(NULL)
+        dnssec_ok_(dnssec_ok), name_(NULL), realname_(NULL)
     {}
 
     /// \brief Constructor for wildcard-expanded owner name.
@@ -122,10 +122,14 @@ public:
     /// \throw std::bad_alloc Memory allocation fails
     TreeNodeRRset(const dns::Name& realname, const dns::RRClass& rrclass,
                   const ZoneNode* node, const RdataSet* rdataset,
-                  bool dnssec_ok);
+                  bool dnssec_ok) :
+        node_(node), rdataset_(rdataset),
+        rrsig_count_(rdataset_->getSigRdataCount()), rrclass_(rrclass),
+        dnssec_ok_(dnssec_ok), name_(NULL), realname_(new dns::Name(realname))
+    {}
 
     virtual ~TreeNodeRRset() {
-        delete[] realname_buf_;
+        delete realname_;
         delete name_;
     }
 
@@ -233,24 +237,19 @@ private:
     dns::LabelSequence getOwnerLabels(
         uint8_t labels_buf[dns::LabelSequence::MAX_SERIALIZED_LENGTH]) const
     {
-        if (realname_buf_ != NULL) {
-            return (dns::LabelSequence(realname_buf_));
+        if (realname_ != NULL) {
+            return (dns::LabelSequence(*realname_));
         }
         return (node_->getAbsoluteLabels(labels_buf));
     }
 
-    // A helper for isSameKind() to check if 'this' and 'other' has
-    // the same "real" name in case at least either is constructed with
-    // a real name.
-    bool hasSameRealName(const TreeNodeRRset& other) const;
-
     const ZoneNode* node_;
     const RdataSet* rdataset_;
     const size_t rrsig_count_;
     const dns::RRClass rrclass_;
     const bool dnssec_ok_;
     mutable dns::Name* name_;
-    uint8_t* realname_buf_;
+    const dns::Name* const realname_;
 };
 
 } // namespace memory