[map] Don't call hash() if map is empty

pull/4264/head
Behdad Esfahbod 1 year ago
parent 735d249639
commit 6a3fcc64f3
  1. 6
      src/hb-map.hh

@ -257,6 +257,7 @@ struct hb_hashmap_t
const V& get_with_hash (const K &key, uint32_t hash) const
{
if (!items) return item_t::default_value ();
auto *item = fetch_item (key, hb_hash (key));
if (item)
return item->value;
@ -264,11 +265,13 @@ struct hb_hashmap_t
}
const V& get (const K &key) const
{
if (!items) return item_t::default_value ();
return get_with_hash (key, hb_hash (key));
}
void del (const K &key)
{
if (!items) return;
auto *item = fetch_item (key, hb_hash (key));
if (item)
{
@ -282,6 +285,7 @@ struct hb_hashmap_t
template <typename VV=V>
bool has (const K &key, VV **vp = nullptr) const
{
if (!items) return false;
auto *item = fetch_item (key, hb_hash (key));
if (item)
{
@ -292,8 +296,6 @@ struct hb_hashmap_t
}
item_t *fetch_item (const K &key, uint32_t hash) const
{
if (!items) return nullptr;
hash &= 0x3FFFFFFF; // We only store lower 30bit of hash
unsigned int i = hash % prime;
unsigned step = 0;

Loading…
Cancel
Save