Browse Source

[1603] comment and variable name cleanup

JINMEI Tatuya 13 years ago
parent
commit
cd8b0868f1
1 changed files with 18 additions and 14 deletions
  1. 18 14
      src/lib/dns/messagerenderer.cc

+ 18 - 14
src/lib/dns/messagerenderer.cc

@@ -37,7 +37,7 @@ namespace {     // hide internal-only names from the public namespaces
 /// \brief The \c OffsetItem class represents a pointer to a name
 /// \brief The \c OffsetItem class represents a pointer to a name
 /// rendered in the internal buffer for the \c MessageRendererImpl object.
 /// rendered in the internal buffer for the \c MessageRendererImpl object.
 ///
 ///
-/// A \c MessageRendererImpl object maintains a set of the \c OffsetItem
+/// A \c MessageRendererImpl object maintains a set of \c OffsetItem
 /// objects in a hash table, and searches the table for the position of the
 /// objects in a hash table, and searches the table for the position of the
 /// longest match (ancestor) name against each new name to be rendered into
 /// longest match (ancestor) name against each new name to be rendered into
 /// the buffer.
 /// the buffer.
@@ -63,12 +63,17 @@ struct OffsetItem {
 /// condition check.
 /// condition check.
 template <bool CASE_SENSITIVE>
 template <bool CASE_SENSITIVE>
 struct NameCompare {
 struct NameCompare {
-    NameCompare(const OutputBuffer& buffer, InputBuffer& data_buf) :
-        buffer_(&buffer), data_buf_(&data_buf)
+    /// \brief Constructor
+    ///
+    /// \param buffer The buffer for rendering used in the caller renderer
+    /// \param name_buf An input buffer storing the wire-format data of the
+    /// name to be newly rendered (and only that data).
+    NameCompare(const OutputBuffer& buffer, InputBuffer& name_buf) :
+        buffer_(&buffer), name_buf_(&name_buf)
     {}
     {}
 
 
     bool operator()(const OffsetItem& item) const {
     bool operator()(const OffsetItem& item) const {
-        if (item.len_ != data_buf_->getLength()) {
+        if (item.len_ != name_buf_->getLength()) {
             return (false);
             return (false);
         }
         }
 
 
@@ -80,13 +85,13 @@ struct NameCompare {
         // position for the subsequent label, taking into account name
         // position for the subsequent label, taking into account name
         // compression, and resets item_label_len to the length of the new
         // compression, and resets item_label_len to the length of the new
         // label.
         // label.
-        data_buf_->setPosition(0);
+        name_buf_->setPosition(0); // buffer can be reused, so reset position
         uint16_t item_pos = item.pos_;
         uint16_t item_pos = item.pos_;
         uint16_t item_label_len = 0;
         uint16_t item_label_len = 0;
         for (size_t i = 0; i < item.len_; ++i, ++item_pos) {
         for (size_t i = 0; i < item.len_; ++i, ++item_pos) {
             item_pos = nextPosition(*buffer_, item_pos, item_label_len);
             item_pos = nextPosition(*buffer_, item_pos, item_label_len);
             const unsigned char ch1 = (*buffer_)[item_pos];
             const unsigned char ch1 = (*buffer_)[item_pos];
-            const unsigned char ch2 = data_buf_->readUint8();
+            const unsigned char ch2 = name_buf_->readUint8();
             if (CASE_SENSITIVE) {
             if (CASE_SENSITIVE) {
                 if (ch1 != ch2) {
                 if (ch1 != ch2) {
                     return (false);
                     return (false);
@@ -128,7 +133,7 @@ private:
     }
     }
 
 
     const OutputBuffer* buffer_;
     const OutputBuffer* buffer_;
-    InputBuffer* data_buf_;
+    InputBuffer* name_buf_;
 };
 };
 }
 }
 
 
@@ -151,8 +156,7 @@ struct MessageRenderer::MessageRendererImpl {
     static const size_t RESERVED_ITEMS = 16;
     static const size_t RESERVED_ITEMS = 16;
     static const uint16_t NO_OFFSET = 65535; // used as a marker of 'not found'
     static const uint16_t NO_OFFSET = 65535; // used as a marker of 'not found'
 
 
-    /// \brief Constructor from an output buffer.
-    ///
+    /// \brief Constructor
     MessageRendererImpl() :
     MessageRendererImpl() :
         msglength_limit_(512), truncated_(false),
         msglength_limit_(512), truncated_(false),
         compress_mode_(MessageRenderer::CASE_INSENSITIVE)
         compress_mode_(MessageRenderer::CASE_INSENSITIVE)
@@ -164,7 +168,7 @@ struct MessageRenderer::MessageRendererImpl {
     }
     }
 
 
     uint16_t findOffset(const OutputBuffer& buffer,
     uint16_t findOffset(const OutputBuffer& buffer,
-                        InputBuffer& data_buf,
+                        InputBuffer& name_buf,
                         size_t bucket_id, bool case_sensitive)
                         size_t bucket_id, bool case_sensitive)
     {
     {
         // Find a matching entry, if any.  We use some heuristics here: often
         // Find a matching entry, if any.  We use some heuristics here: often
@@ -176,11 +180,11 @@ struct MessageRenderer::MessageRendererImpl {
         if (case_sensitive) {
         if (case_sensitive) {
             found = find_if(table_[bucket_id].rbegin(),
             found = find_if(table_[bucket_id].rbegin(),
                             table_[bucket_id].rend(),
                             table_[bucket_id].rend(),
-                            NameCompare<true>(buffer, data_buf));
+                            NameCompare<true>(buffer, name_buf));
         } else {
         } else {
             found = find_if(table_[bucket_id].rbegin(),
             found = find_if(table_[bucket_id].rbegin(),
                             table_[bucket_id].rend(),
                             table_[bucket_id].rend(),
-                            NameCompare<false>(buffer, data_buf));
+                            NameCompare<false>(buffer, name_buf));
         }
         }
         if (found != table_[bucket_id].rend()) {
         if (found != table_[bucket_id].rend()) {
             return (found->pos_);
             return (found->pos_);
@@ -298,8 +302,8 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
         bucket_ids[nlabels_uncomp] =
         bucket_ids[nlabels_uncomp] =
             (sequence.getHash(impl_->compress_mode_) %
             (sequence.getHash(impl_->compress_mode_) %
              MessageRendererImpl::BUCKETS);
              MessageRendererImpl::BUCKETS);
-        InputBuffer data_buf(data, data_len);
-        ptr_offset = impl_->findOffset(getBuffer(), data_buf,
+        InputBuffer name_buf(data, data_len);
+        ptr_offset = impl_->findOffset(getBuffer(), name_buf,
                                        bucket_ids[nlabels_uncomp],
                                        bucket_ids[nlabels_uncomp],
                                        case_sensitive);
                                        case_sensitive);
         if (ptr_offset != MessageRendererImpl::NO_OFFSET) {
         if (ptr_offset != MessageRendererImpl::NO_OFFSET) {