From 3ff8abf27287da410883b0f4305cb9426206a60f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 18 Nov 2022 19:35:49 -0700 Subject: [PATCH] Revert "[map] Allow std::move-ing keys into the map" This reverts commit f657ef7e57c889309c2d9d37934368ca255f9d5b. This breaks many compilers with messages like this: hb-subset-plan.hh:226: undefined reference to `OT::head::tableTag' I'm out of my depth re how to fix it. --- src/hb-map.hh | 15 ++++++--------- src/test-map.cc | 6 ++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 796b068ed..9bfe338eb 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -186,7 +186,7 @@ struct hb_hashmap_t { if (old_items[i].is_real ()) { - set_with_hash (std::move (old_items[i].key), + set_with_hash (old_items[i].key, old_items[i].hash, std::move (old_items[i].value)); } @@ -199,9 +199,7 @@ struct hb_hashmap_t } template - bool set (const K &key, VV&& value) { return set_with_hash (hb_ridentity (key), hb_hash (key), std::forward (value)); } - template - bool set (K&& key, VV&& value) { return set_with_hash (std::move (key), hb_hash (key), std::forward (value)); } + bool set (K key, VV&& value) { return set_with_hash (key, hb_hash (key), std::forward (value)); } const V& get (K key) const { @@ -210,8 +208,7 @@ struct hb_hashmap_t return item.is_real () && item == key ? item.value : item_t::default_value (); } - void del (const K &key) { set_with_hash (hb_ridentity (key), hb_hash (key), item_t::default_value (), true); } - void del (K&& key) { set_with_hash (std::move (key), hb_hash (key), item_t::default_value (), true); } + void del (K key) { set_with_hash (key, hb_hash (key), item_t::default_value (), true); } /* Has interface. */ typedef const V& value_t; @@ -327,8 +324,8 @@ struct hb_hashmap_t protected: - template - bool set_with_hash (KK&& key, uint32_t hash, VV&& value, bool is_delete=false) + template + bool set_with_hash (K key, uint32_t hash, VV&& value, bool is_delete=false) { if (unlikely (!successful)) return false; if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false; @@ -344,7 +341,7 @@ struct hb_hashmap_t population--; } - item.key = std::forward (key); + item.key = key; item.value = std::forward (value); item.hash = hash; item.set_used (true); diff --git a/src/test-map.cc b/src/test-map.cc index 3e40513e0..12455ea8e 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -228,8 +228,10 @@ main (int argc, char **argv) { hb_hashmap_t, hb::unique_ptr> m; - m.set (hb::unique_ptr (hb_set_get_empty ()), - hb::unique_ptr (hb_set_get_empty ())); + // Doesn't work. + // See commit f657ef7e57c889309c2d9d37934368ca255f9d5b and its revert. + //m.set (hb::unique_ptr (hb_set_get_empty ()), + // hb::unique_ptr (hb_set_get_empty ())); m.get (hb::unique_ptr (hb_set_get_empty ())); m.iter_ref (); m.keys_ref ();