diff --git a/src/hb-map.hh b/src/hb-map.hh index 1b6a7bf4b..e89c3e9eb 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -205,7 +205,7 @@ struct hb_hashmap_t } template - bool set_with_hash (KK&& key, uint32_t hash, VV&& value) + bool set_with_hash (KK&& key, uint32_t hash, VV&& value, bool overwrite = true) { if (unlikely (!successful)) return false; if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false; @@ -219,7 +219,12 @@ struct hb_hashmap_t { if ((std::is_integral::value || items[i].hash == hash) && items[i] == key) - break; + { + if (!overwrite) + return false; + else + break; + } if (items[i].is_tombstone () && tombstone == (unsigned) -1) tombstone = i; i = (i + ++step) & mask; @@ -251,9 +256,9 @@ struct hb_hashmap_t } template - bool set (const K &key, VV&& value) { return set_with_hash (key, hb_hash (key), std::forward (value)); } + bool set (const K &key, VV&& value, bool overwrite = true) { return set_with_hash (key, hb_hash (key), std::forward (value), overwrite); } 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, bool overwrite = true) { return set_with_hash (std::move (key), hb_hash (key), std::forward (value), overwrite); } const V& get_with_hash (const K &key, uint32_t hash) const { diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 308bb5944..1f40ea4cd 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -46,11 +46,11 @@ struct remap_sid_t : hb_map_t if ((sid != CFF_UNDEF_SID) && !is_std_std (sid)) { sid = unoffset_sid (sid); - unsigned v = get (sid); - if (v != HB_MAP_VALUE_INVALID) - return offset_sid (v); - v = next++; - set (sid, v); + unsigned v = next; + if (set (sid, v, false)) + next++; + else + v = get (sid); // already exists return offset_sid (v); } else