[cache] Use short instead of int if fits

This commit is contained in:
Behdad Esfahbod 2022-08-03 13:19:33 -06:00
parent d831e935df
commit 99070a734a
1 changed files with 6 additions and 3 deletions

View File

@ -38,11 +38,15 @@ template <unsigned int key_bits=16,
bool thread_safe=true> bool thread_safe=true>
struct hb_cache_t struct hb_cache_t
{ {
using item_t = typename std::conditional<thread_safe, hb_atomic_int_t, int>::type; using item_t = typename std::conditional<thread_safe,
hb_atomic_int_t,
typename std::conditional<key_bits + value_bits - cache_bits <= 16,
short,
int>::type
>::type;
static_assert ((key_bits >= cache_bits), ""); static_assert ((key_bits >= cache_bits), "");
static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (item_t)), ""); static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (item_t)), "");
static_assert (sizeof (item_t) == sizeof (unsigned int), "");
void init () { clear (); } void init () { clear (); }
void fini () {} void fini () {}
@ -78,7 +82,6 @@ struct hb_cache_t
item_t values[1u<<cache_bits]; item_t values[1u<<cache_bits];
}; };
template <bool thread_safe = true> template <bool thread_safe = true>
using hb_cmap_cache_t = hb_cache_t<21, 16, 8, thread_safe>; using hb_cmap_cache_t = hb_cache_t<21, 16, 8, thread_safe>;