From 45b6340a982926f8441486c1c81ed49da32bd639 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 3 Sep 2012 20:03:55 +0000 Subject: [PATCH] Unordered: Avoid allocating nodes in table constructor. [SVN r80384] --- include/boost/unordered/detail/equivalent.hpp | 13 +++++++--- include/boost/unordered/detail/table.hpp | 26 ++++++++++++------- include/boost/unordered/detail/unique.hpp | 13 +++++++--- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 177fc86f..d198d9d4 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -204,12 +204,17 @@ namespace boost { namespace unordered { namespace detail { grouped_table_impl(grouped_table_impl const& x) : table(x, node_allocator_traits:: - select_on_container_copy_construction(x.node_alloc())) {} + select_on_container_copy_construction(x.node_alloc())) + { + this->init(x); + } grouped_table_impl(grouped_table_impl const& x, node_allocator const& a) : table(x, a) - {} + { + this->init(x); + } grouped_table_impl(grouped_table_impl& x, boost::unordered::detail::move_tag m) @@ -220,7 +225,9 @@ namespace boost { namespace unordered { namespace detail { node_allocator const& a, boost::unordered::detail::move_tag m) : table(x, a, m) - {} + { + this->move_init(x); + } // Accessors diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index 24035a8a..ac758907 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -235,14 +235,7 @@ namespace boost { namespace unordered { namespace detail { functions(x), mlf_(x.mlf_), max_load_(0) - { - if(x.size_) { - this->create_buckets(this->bucket_count_); - copy_nodes copy(this->node_alloc()); - table_impl::fill_buckets(x.get_start(), *this, copy); - this->max_load_ = calculate_max_load(); - } - } + {} // TODO: Why calculate_max_load? table(table& x, boost::unordered::detail::move_tag m) : @@ -260,8 +253,23 @@ namespace boost { namespace unordered { namespace detail { functions(x), mlf_(x.mlf_), max_load_(x.max_load_) + {} + + // Initialisation. + + void init(table const& x) { - if(a == x.node_alloc()) { + if (x.size_) { + this->create_buckets(this->bucket_count_); + copy_nodes copy(this->node_alloc()); + table_impl::fill_buckets(x.get_start(), *this, copy); + this->max_load_ = calculate_max_load(); + } + } + + void move_init(table& x) + { + if(this->node_alloc() == x.node_alloc()) { this->move_buckets_from(x); } else if(x.size_) { diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index 37f70466..533e40a8 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -202,12 +202,17 @@ namespace boost { namespace unordered { namespace detail { table_impl(table_impl const& x) : table(x, node_allocator_traits:: - select_on_container_copy_construction(x.node_alloc())) {} + select_on_container_copy_construction(x.node_alloc())) + { + this->init(x); + } table_impl(table_impl const& x, node_allocator const& a) : table(x, a) - {} + { + this->init(x); + } table_impl(table_impl& x, boost::unordered::detail::move_tag m) @@ -218,7 +223,9 @@ namespace boost { namespace unordered { namespace detail { node_allocator const& a, boost::unordered::detail::move_tag m) : table(x, a, m) - {} + { + this->move_init(x); + } // Accessors