From b9230c542558afac93f1fb6d7ca1442a06688d38 Mon Sep 17 00:00:00 2001
From: Behdad Esfahbod <behdad@behdad.org>
Date: Thu, 2 Jun 2022 11:18:38 -0600
Subject: [PATCH] [map] Fix has()

---
 src/hb-map.hh | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/hb-map.hh b/src/hb-map.hh
index fb3d2d1c7..065ae1731 100644
--- a/src/hb-map.hh
+++ b/src/hb-map.hh
@@ -213,11 +213,24 @@ struct hb_hashmap_t
   /* Has interface. */
   typedef V value_t;
   value_t operator [] (K k) const { return get (k); }
-  bool has (K k, V *vp = nullptr) const
+  bool has (K key, V *vp = nullptr) const
   {
-    const V &v = (*this)[k];
-    if (vp) *vp = v;
-    return v != item_t::default_value (); // TODO
+    if (unlikely (!items))
+    {
+      if (vp) *vp = item_t::default_value ();
+      return false;
+    }
+    unsigned int i = bucket_for (key);
+    if (items[i].is_real () && items[i] == key)
+    {
+      if (vp) *vp = items[i].value;
+      return true;
+    }
+    else
+    {
+      if (vp) *vp = item_t::default_value ();
+      return false;
+    }
   }
   /* Projection. */
   V operator () (K k) const { return get (k); }