From b3f2ebedbcb1003c609b6c891a44c013cb60953c Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Fri, 7 Dec 2012 03:10:22 +0000 Subject: [PATCH] Special case array construction for trivially default-constructible types and array destruction for trivially-destroyable types. [SVN r81749] --- .../boost/smart_ptr/detail/array_utility.hpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/boost/smart_ptr/detail/array_utility.hpp b/include/boost/smart_ptr/detail/array_utility.hpp index d24bea1..05bca19 100644 --- a/include/boost/smart_ptr/detail/array_utility.hpp +++ b/include/boost/smart_ptr/detail/array_utility.hpp @@ -17,12 +17,32 @@ namespace boost { namespace detail { template inline void array_destroy(T* memory, std::size_t size) { + boost::has_trivial_destructor type; + array_destroy(memory, size, type); + } + template + inline void array_destroy(T*, std::size_t, boost::true_type) { + } + template + inline void array_destroy(T* memory, std::size_t size, boost::false_type) { for (std::size_t i = size; i > 0; ) { memory[--i].~T(); } } template inline void array_construct(T* memory, std::size_t size) { + boost::has_trivial_default_constructor type; + array_construct(memory, size, type); + } + template + inline void array_construct(T* memory, std::size_t size, boost::true_type) { + for (std::size_t i = 0; i < size; i++) { + void* p1 = memory + i; + ::new(p1) T(); + } + } + template + inline void array_construct(T* memory, std::size_t size, boost::false_type) { std::size_t i = 0; try { for (; i < size; i++) { @@ -92,6 +112,14 @@ namespace boost { } template inline void array_construct_noinit(T* memory, std::size_t size) { + boost::has_trivial_default_constructor type; + array_construct_noinit(memory, size, type); + } + template + inline void array_construct_noinit(T*, std::size_t, boost::true_type) { + } + template + inline void array_construct_noinit(T* memory, std::size_t size, boost::false_type) { std::size_t i = 0; try { for (; i < size; i++) {