forked from boostorg/unordered
use memset for group array initialization only when permissible
This commit is contained in:
@ -163,11 +163,12 @@ static constexpr std::size_t default_bucket_count=0;
|
|||||||
* "logical" 128-bit word, and so forth. With this layout, match can be
|
* "logical" 128-bit word, and so forth. With this layout, match can be
|
||||||
* implemented with 4 ANDs, 3 shifts, 2 XORs, 1 OR and 1 NOT.
|
* implemented with 4 ANDs, 3 shifts, 2 XORs, 1 OR and 1 NOT.
|
||||||
*
|
*
|
||||||
* TODO: Explain IntegralWrapper.
|
* IntegralWrapper<Integral> is used to implement group15's underlying
|
||||||
*
|
* metadata: it behaves as a plain integral for foa::table or introduces
|
||||||
* group15 has no user-defined ctor so that it's a trivial type and can be
|
* atomic ops for foa::concurrent_table. If IntegralWrapper<...> is trivially
|
||||||
* initialized via memset etc. Where needed, group15::initialize sets the
|
* constructible, so is group15, in which case it can be initialized via memset
|
||||||
* metadata to all zeros.
|
* etc. Where needed, group15::initialize resets the metadata to the all
|
||||||
|
* zeros (default state).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(BOOST_UNORDERED_SSE2)
|
#if defined(BOOST_UNORDERED_SSE2)
|
||||||
@ -937,10 +938,10 @@ struct table_arrays
|
|||||||
reinterpret_cast<uintptr_t>(p))%sizeof(group_type);
|
reinterpret_cast<uintptr_t>(p))%sizeof(group_type);
|
||||||
arrays.groups=reinterpret_cast<group_type*>(p);
|
arrays.groups=reinterpret_cast<group_type*>(p);
|
||||||
|
|
||||||
/* memset is faster/not slower than initializing groups individually.
|
initialize_groups(
|
||||||
* This assumes all zeros is group_type's default layout.
|
arrays.groups,groups_size,
|
||||||
*/
|
std::integral_constant<
|
||||||
std::memset(arrays.groups,0,sizeof(group_type)*groups_size);
|
bool,std::is_trivially_constructible<group_type>::value>{});
|
||||||
arrays.groups[groups_size-1].set_sentinel();
|
arrays.groups[groups_size-1].set_sentinel();
|
||||||
}
|
}
|
||||||
return arrays;
|
return arrays;
|
||||||
@ -976,6 +977,22 @@ struct table_arrays
|
|||||||
return (buffer_bytes+sizeof(value_type)-1)/sizeof(value_type);
|
return (buffer_bytes+sizeof(value_type)-1)/sizeof(value_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void initialize_groups(
|
||||||
|
group_type* groups_,std::size_t size,std::true_type /* memset */)
|
||||||
|
{
|
||||||
|
/* Faster/not slower than manual, assumes all zeros is group_type's
|
||||||
|
* default layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::memset(groups_,0,sizeof(group_type)*size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initialize_groups(
|
||||||
|
group_type* groups_,std::size_t size,std::false_type /* manual */)
|
||||||
|
{
|
||||||
|
while(size--!=0)::new (groups_++) group_type();
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t groups_size_index;
|
std::size_t groups_size_index;
|
||||||
std::size_t groups_size_mask;
|
std::size_t groups_size_mask;
|
||||||
group_type *groups;
|
group_type *groups;
|
||||||
|
Reference in New Issue
Block a user