From ef33b5d1f6d3ec21e15ad74ca2524a117f594e06 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Mar 2019 14:39:21 -0700 Subject: [PATCH] [map] Deref pointers before equality check --- src/hb-map.hh | 6 ++++-- src/hb-meta.hh | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 406730831..d36515a74 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -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; diff --git a/src/hb-meta.hh b/src/hb-meta.hh index ef139fad2..a303c67a7 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -66,9 +66,9 @@ template struct hb_match_pointer { typedef T type; enum { valu static const struct { template - T& operator () (T v) { return v; } + T operator () (T v) const { return v; } template - T& operator () (T *v) { return *v; } + T& operator () (T *v) const { return *v; } } hb_deref_pointer HB_UNUSED;