]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2098] use a real name object for real name instead of serialized labelseqs
authorJINMEI Tatuya <jinmei@isc.org>
Fri, 31 Aug 2012 01:16:15 +0000 (10:16 +0900)
committerJINMEI Tatuya <jinmei@isc.org>
Fri, 31 Aug 2012 01:16:15 +0000 (10:16 +0900)
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.

src/lib/datasrc/memory/treenode_rrset.cc
src/lib/datasrc/memory/treenode_rrset.h

index 11898a3f26683800f13c8bac12491e5f1a7200bd..c6219781a5a9b6ad4c34b2ae36f4baef7da2c38e 100644 (file)
@@ -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
index 1f521243868e02c459cd4f8de102ee0dfd511cd4..7567ae16a5dda769652f4d0131001569b4d5abc3 100644 (file)
@@ -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