From cf20d2ec5d609a5a9319b5b1f6cdf5616d41d13d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 21 Nov 2022 20:46:01 -0700 Subject: [PATCH] [map] Take const key --- src/hb-map.hh | 10 +++++----- src/hb-subset-plan.hh | 6 +++--- src/test-map.cc | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 6794a1ef8..b08c3f382 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -199,7 +199,7 @@ struct hb_hashmap_t } template - bool set_with_hash (K key, uint32_t hash, VV&& value, bool is_delete=false) + bool set_with_hash (const 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; @@ -229,21 +229,21 @@ struct hb_hashmap_t } template - bool set (K key, VV&& value) { return set_with_hash (key, hb_hash (key), std::forward (value)); } + bool set (const K &key, VV&& value) { return set_with_hash (key, hb_hash (key), std::forward (value)); } - const V& get_with_hash (K key, uint32_t hash) const + const V& get_with_hash (const K &key, uint32_t hash) const { if (unlikely (!items)) return item_t::default_value (); auto &item = item_for_hash (key, hash); return item.is_real () && item == key ? item.value : item_t::default_value (); } - const V& get (K key) const + const V& get (const K &key) const { if (unlikely (!items)) return item_t::default_value (); return get_with_hash (key, hb_hash (key)); } - void del (K key) { set_with_hash (key, hb_hash (key), item_t::default_value (), true); } + void del (const K &key) { set_with_hash (key, hb_hash (key), item_t::default_value (), true); } /* Has interface. */ typedef const V& value_t; diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 55d2dcd4d..47f913dfd 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -216,15 +216,15 @@ struct hb_subset_plan_t { if (sanitized_table_cache && !sanitized_table_cache->in_error () - && sanitized_table_cache->has (T::tableTag)) { - return hb_blob_reference (sanitized_table_cache->get (T::tableTag).get ()); + && sanitized_table_cache->has (0+T::tableTag)) { + return hb_blob_reference (sanitized_table_cache->get (0+T::tableTag).get ()); } hb::unique_ptr table_blob {hb_sanitize_context_t ().reference_table (source)}; hb_blob_t* ret = hb_blob_reference (table_blob.get ()); if (likely (sanitized_table_cache)) - sanitized_table_cache->set (T::tableTag, + sanitized_table_cache->set (0+T::tableTag, std::move (table_blob)); return ret; diff --git a/src/test-map.cc b/src/test-map.cc index acd5d7cc1..12455ea8e 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -232,7 +232,7 @@ main (int argc, char **argv) // 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.get (hb::unique_ptr (hb_set_get_empty ())); m.iter_ref (); m.keys_ref (); m.values_ref ();