[map] Deref pointers before equality check

This commit is contained in:
Behdad Esfahbod 2019-03-30 14:39:21 -07:00
parent c98f51da71
commit ef33b5d1f6
2 changed files with 6 additions and 4 deletions

View File

@ -51,6 +51,8 @@ struct hb_hashmap_t
K key;
V value;
bool operator== (K o) { return hb_deref_pointer (key) == hb_deref_pointer (o); }
bool operator== (const item_t &o) { return *this == o.key; }
bool is_unused () const { return key == kINVALID; }
bool is_tombstone () const { return key != kINVALID && value == vINVALID; }
};
@ -153,7 +155,7 @@ struct hb_hashmap_t
{
if (unlikely (!items)) return vINVALID;
unsigned int i = bucket_for (key);
return items[i].key == key ? items[i].value : vINVALID;
return items[i] == key ? items[i].value : vINVALID;
}
void del (K key) { set (key, vINVALID); }
@ -185,7 +187,7 @@ struct hb_hashmap_t
unsigned int tombstone = (unsigned) -1;
while (!items[i].is_unused ())
{
if (items[i].key == key)
if (items[i] == key)
return i;
if (tombstone == (unsigned) -1 && items[i].is_tombstone ())
tombstone = i;

View File

@ -66,9 +66,9 @@ template <typename T> struct hb_match_pointer<T *> { typedef T type; enum { valu
static const struct
{
template <typename T>
T& operator () (T v) { return v; }
T operator () (T v) const { return v; }
template <typename T>
T& operator () (T *v) { return *v; }
T& operator () (T *v) const { return *v; }
} hb_deref_pointer HB_UNUSED;