Browse Source

[1603] simplified the part of trimming exceessive renderer table space.

since we don't have to preserve the existing item in this context, we can
simply swap the current vector with a newly created (with a reserved space)
vector.
JINMEI Tatuya 13 years ago
parent
commit
4dbcf3b666
1 changed files with 5 additions and 6 deletions
  1. 5 6
      src/lib/dns/messagerenderer.cc

+ 5 - 6
src/lib/dns/messagerenderer.cc

@@ -242,12 +242,11 @@ MessageRenderer::clear() {
     // subsequent use of the renderer.
     for (size_t i = 0; i < MessageRendererImpl::BUCKETS; ++i) {
         if (impl_->table_[i].size() > MessageRendererImpl::RESERVED_ITEMS) {
-            // Trim excessive capacity: reserve() invalidates the excessive
-            // items, and swap ensures the new capacity is only reasonably
-            // large for the reserved space.
-            impl_->table_[i].reserve(MessageRendererImpl::RESERVED_ITEMS);
-            vector<OffsetItem>(impl_->table_[i].begin(),
-                               impl_->table_[i].end()).swap(impl_->table_[i]);
+            // Trim excessive capacity: swap ensures the new capacity is only
+            // reasonably large for the reserved space.
+            vector<OffsetItem> new_table;
+            new_table.reserve(MessageRendererImpl::RESERVED_ITEMS);
+            new_table.swap(impl_->table_[i]);
         }
         impl_->table_[i].clear();
     }