mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[map] Shuffle fetch_item
This commit is contained in:
1 parent
1dc99128b9
commit
2ffec3a6f4
1 file changed
+16
-12
+16
-12
@@ -237,8 +237,10 @@ struct hb_hashmap_t
|
||||
|
||||
const V& get_with_hash (const K &key, uint32_t hash) const
|
||||
{
|
||||
const V* v;
|
||||
return has_with_hash (key, hash, &v) ? *v : item_t::default_value ();
|
||||
auto *item = fetch_item (key, hb_hash (key));
|
||||
if (item)
|
||||
return item->value;
|
||||
return item_t::default_value ();
|
||||
}
|
||||
const V& get (const K &key) const
|
||||
{
|
||||
@@ -252,12 +254,17 @@ struct hb_hashmap_t
|
||||
template <typename VV=V>
|
||||
bool has (const K &key, VV **vp = nullptr) const
|
||||
{
|
||||
return has_with_hash (key, hb_hash (key), vp);
|
||||
auto *item = fetch_item (key, hb_hash (key));
|
||||
if (item)
|
||||
{
|
||||
if (vp) *vp = std::addressof (item->value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
template <typename VV=V>
|
||||
bool has_with_hash (const K &key, uint32_t hash, VV **vp = nullptr) const
|
||||
item_t *fetch_item (const K &key, uint32_t hash) const
|
||||
{
|
||||
if (unlikely (!items)) return false;
|
||||
if (unlikely (!items)) return nullptr;
|
||||
|
||||
hash &= 0x3FFFFFFF; // We only store lower 30bit of hash
|
||||
unsigned int i = hash % prime;
|
||||
@@ -267,16 +274,13 @@ struct hb_hashmap_t
|
||||
items[i] == key)
|
||||
{
|
||||
if (items[i].is_real ())
|
||||
{
|
||||
if (vp) *vp = std::addressof (items[i].value);
|
||||
return true;
|
||||
}
|
||||
return &items[i];
|
||||
else
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
i = (i + 1) & mask;
|
||||
}
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
/* Projection. */
|
||||
V operator () (K k) const { return get (k); }
|
||||
|
||||
Reference in new issue
Block a user