Commits

ssn...@4525493e-7705-40b1-a816-d608a930855b  committed f57232b

Avoid copying allocator in node allocation/deallocation.

  • Participants
  • Parent commits ee16823

Comments (0)

Files changed (2)

+2011-10-16  scott snyder  <snyder@bnl.gov>
+
+	* Tagging CxxUtils-00-00-81.
+	* CxxUtils/hashtable.h: Avoid copying allocator in node
+	allocation/deallocation.
+
 2011-07-21  Rolf Seuster < seuster AT cern.ch>
 	* fix problem in SealDebug.cxx
 	* no line numbers

File CxxUtils/hashtable.h

 
     private:
       node_allocator_t m_node_allocator;
+      // sss -- Some of our allocators have non-trivial state, and
+      // thus a non-trivial copy ctor.  However, m_allocate_node
+      // will do a copy conversion of node_allocator_t to allocator_type
+      // for each node allocated.  Instead, do the conversion once
+      // and cache it.  Note: in newer gcc versions, extensions to the
+      // allocator model allow dispensing with the conversions.  So once
+      // we go to c++0x, this shouldn't be an issue.
+      allocator_type m_payload_allocator;
       node** m_buckets;
       size_type m_bucket_count;
       size_type m_element_count;
     {
       node* n = m_node_allocator.allocate(1);
       try
-	{
-	  get_allocator().construct(&n->m_v, v);
+      {
+          m_payload_allocator.construct(&n->m_v, v);
 	  n->m_next = 0;
 	  return n;
 	}
     hashtable<K, V, A, Ex, Eq, H1, H2, H, RP, c, ci, u>::
     m_deallocate_node(node* n)
     {
-      get_allocator().destroy(&n->m_v);
+      m_payload_allocator.destroy(&n->m_v);
       m_node_allocator.deallocate(n, 1);
     }
 
       Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c>(exk, eq, h1, h2, h),
       Internal::map_base<K, V, Ex, u, hashtable>(),
       m_node_allocator(a),
+      m_payload_allocator(a),
       m_bucket_count(0),
       m_element_count(0),
       m_rehash_policy()
       Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c>(ht),
       Internal::map_base<K, V, Ex, u, hashtable>(ht),
       m_node_allocator(ht.get_allocator()),
+      m_payload_allocator(ht.get_allocator()),
       m_bucket_count(ht.m_bucket_count),
       m_element_count(ht.m_element_count),
       m_rehash_policy(ht.m_rehash_policy)