From f76b4963b5b60af1499389734929e683501b5bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 29 Apr 2018 12:02:07 +0200 Subject: [PATCH] Optimize case with 256 keys or less. --- include/boost/move/algo/adaptive_sort.hpp | 15 ++++++++++++--- .../move/algo/detail/adaptive_sort_merge.hpp | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/boost/move/algo/adaptive_sort.hpp b/include/boost/move/algo/adaptive_sort.hpp index 2026f9c..4f50bf1 100644 --- a/include/boost/move/algo/adaptive_sort.hpp +++ b/include/boost/move/algo/adaptive_sort.hpp @@ -292,9 +292,18 @@ bool adaptive_sort_combine_all_blocks //Combine to form l_merged*2 segments if(n_keys){ - adaptive_sort_combine_blocks - ( keys, comp, !use_internal_buf || is_merge_left ? first : first-l_block - , l_data, l_merged, l_block, use_internal_buf, common_xbuf, xbuf, comp, is_merge_left); + size_type upper_n_keys_this_iter = 2*l_merged/l_block; + if(upper_n_keys_this_iter > 256){ + adaptive_sort_combine_blocks + ( keys, comp, !use_internal_buf || is_merge_left ? first : first-l_block + , l_data, l_merged, l_block, use_internal_buf, common_xbuf, xbuf, comp, is_merge_left); + } + else{ + unsigned char uint_keys[256]; + adaptive_sort_combine_blocks + ( uint_keys, less(), !use_internal_buf || is_merge_left ? first : first-l_block + , l_data, l_merged, l_block, use_internal_buf, common_xbuf, xbuf, comp, is_merge_left); + } } else{ size_type *const uint_keys = xbuf.template aligned_trailing(); diff --git a/include/boost/move/algo/detail/adaptive_sort_merge.hpp b/include/boost/move/algo/detail/adaptive_sort_merge.hpp index 1606fde..4c28086 100644 --- a/include/boost/move/algo/detail/adaptive_sort_merge.hpp +++ b/include/boost/move/algo/detail/adaptive_sort_merge.hpp @@ -868,7 +868,7 @@ void initialize_keys( RandIt first, RandIt last typedef typename iterator_traits::value_type value_type; std::size_t count = std::size_t(last - first); for(std::size_t i = 0; i != count; ++i){ - *first = value_type(i); + *first = static_cast(i); ++first; } }