]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1603] simplified the part of trimming exceessive renderer table space.
authorJINMEI Tatuya <jinmei@isc.org>
Mon, 12 Mar 2012 05:33:09 +0000 (22:33 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Mon, 12 Mar 2012 05:33:09 +0000 (22:33 -0700)
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.

src/lib/dns/messagerenderer.cc

index e704ba0ca14eeacd3c4c66c290d9f8af26e28b7b..1f087f84469e016b01b893e7303ff96e3dc214ea 100644 (file)
@@ -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();
     }