From 371e14d99c6c84e11d71957c55b536530db1e415 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 28 May 2022 13:40:30 -0600 Subject: [PATCH] Combine uses of map has() then get() with has(.., &..) --- src/hb-ot-color-cpal-table.hh | 5 +++-- src/hb-ot-layout-common.hh | 3 ++- src/hb-ot-post-table-v2subset.hh | 3 +-- src/hb-repacker.hh | 18 +++++++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index 24476eda1..201fa3e46 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -97,9 +97,10 @@ struct CPALV1Tail c->push (); for (const auto _ : colorLabels) { - if (!color_index_map->has (_)) continue; + hb_codepoint_t v; + if (!color_index_map->has (_, &v)) continue; NameID new_color_idx; - new_color_idx = color_index_map->get (_); + new_color_idx = v; if (!c->copy (new_color_idx)) { c->pop_discard (); diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 7b3a88ccf..cf2658486 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -659,7 +659,8 @@ struct LangSys auto *out = c->serializer->start_embed (*this); if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false); - out->reqFeatureIndex = l->feature_index_map->has (reqFeatureIndex) ? l->feature_index_map->get (reqFeatureIndex) : 0xFFFFu; + unsigned v; + out->reqFeatureIndex = l->feature_index_map->has (reqFeatureIndex, &v) ? v : 0xFFFFu; if (!l->visitFeatureIndex (featureIndex.len)) return_trace (false); diff --git a/src/hb-ot-post-table-v2subset.hh b/src/hb-ot-post-table-v2subset.hh index 0f3cd8e24..c817b28e6 100644 --- a/src/hb-ot-post-table-v2subset.hh +++ b/src/hb-ot-post-table-v2subset.hh @@ -86,8 +86,7 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const unsigned new_index; if (old_index <= 257) new_index = old_index; - else if (old_new_index_map.has (old_index)) new_index = old_new_index_map.get (old_index); - else + else if (!old_new_index_map.has (old_index, &new_index)) { hb_bytes_t s = _post.find_glyph_name (old_gid); new_index = glyph_name_to_new_index.get (s); diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index ce9ff90bb..726a6e84f 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -430,7 +430,8 @@ struct graph_t auto new_subgraph = + subgraph.keys () | hb_map([&] (unsigned node_idx) { - if (index_map.has (node_idx)) return index_map[node_idx]; + unsigned v; + if (index_map.has (node_idx, &v)) return v; return node_idx; }) ; @@ -442,10 +443,11 @@ struct graph_t unsigned next = HB_SET_VALUE_INVALID; while (roots.next (&next)) { - if (index_map.has (next)) + unsigned v; + if (index_map.has (next, &v)) { roots.del (next); - roots.add (index_map[next]); + roots.add (v); } } @@ -456,9 +458,10 @@ struct graph_t { for (const auto& link : vertices_[node_idx].obj.all_links ()) { - if (subgraph.has (link.objidx)) + unsigned v; + if (subgraph.has (link.objidx, &v)) { - subgraph.set (link.objidx, subgraph[link.objidx] + 1); + subgraph.set (link.objidx, v + 1); continue; } subgraph.set (link.objidx, 1); @@ -940,10 +943,11 @@ struct graph_t { for (auto& link : vertices_[i].obj.all_links_writer ()) { - if (!id_map.has (link.objidx)) continue; + unsigned v; + if (!id_map.has (link.objidx, &v)) continue; if (only_wide && !(link.width == 4 && !link.is_signed)) continue; - reassign_link (link, i, id_map[link.objidx]); + reassign_link (link, i, v); } } }