From 393f0f9f16944654ddd2235eacef20951ce598b7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 25 Jun 2023 18:14:56 -0600 Subject: [PATCH] [map] Rename resize() to alloc() Better matches the functionality, and hb_vector_t. --- src/hb-bimap.hh | 10 +++++----- src/hb-map.hh | 12 ++++++------ src/hb-multimap.hh | 4 ++-- src/hb-ot-cmap-table.hh | 2 +- src/hb-ot-post-table-v2subset.hh | 6 +++--- src/hb-subset-accelerator.hh | 2 +- src/hb-subset-cff-common.hh | 2 +- src/hb-subset-cff1.cc | 6 +++--- src/hb-subset-plan.cc | 10 +++++----- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index 2e1af30d0..f69009328 100644 --- a/src/hb-bimap.hh +++ b/src/hb-bimap.hh @@ -39,10 +39,10 @@ struct hb_bimap_t back_map.reset (); } - void resize (unsigned pop) + void alloc (unsigned pop) { - forw_map.resize (pop); - back_map.resize (pop); + forw_map.alloc (pop); + back_map.alloc (pop); } bool in_error () const { return forw_map.in_error () || back_map.in_error (); } @@ -144,10 +144,10 @@ struct hb_inc_bimap_t : hb_bimap_t { hb_codepoint_t count = get_population (); hb_vector_t work; - work.resize (count); + if (unlikely (!work.resize (count, false))) return; for (hb_codepoint_t rhs = 0; rhs < count; rhs++) - work[rhs] = back_map[rhs]; + work.arrayZ[rhs] = back_map[rhs]; work.qsort (cmp_id); diff --git a/src/hb-map.hh b/src/hb-map.hh index 65e9191ba..f5a03668f 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -45,9 +45,9 @@ struct hb_hashmap_t hb_hashmap_t () { init (); } ~hb_hashmap_t () { fini (); } - hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { resize (o.population); hb_copy (o, *this); } + hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { alloc (o.population); hb_copy (o, *this); } hb_hashmap_t (hb_hashmap_t&& o) : hb_hashmap_t () { hb_swap (*this, o); } - hb_hashmap_t& operator= (const hb_hashmap_t& o) { reset (); resize (o.population); hb_copy (o, *this); return *this; } + hb_hashmap_t& operator= (const hb_hashmap_t& o) { reset (); alloc (o.population); hb_copy (o, *this); return *this; } hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; } hb_hashmap_t (std::initializer_list> lst) : hb_hashmap_t () @@ -61,7 +61,7 @@ struct hb_hashmap_t { auto iter = hb_iter (o); if (iter.is_random_access_iterator || iter.has_fast_len) - resize (hb_len (iter)); + alloc (hb_len (iter)); hb_copy (iter, *this); } @@ -166,7 +166,7 @@ struct hb_hashmap_t bool in_error () const { return !successful; } - bool resize (unsigned new_population = 0) + bool alloc (unsigned new_population = 0) { if (unlikely (!successful)) return false; @@ -218,7 +218,7 @@ struct hb_hashmap_t 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; + if (unlikely ((occupancy + occupancy / 2) >= mask && !alloc ())) return false; hash &= 0x3FFFFFFF; // We only store lower 30bit of hash unsigned int tombstone = (unsigned int) -1; @@ -259,7 +259,7 @@ struct hb_hashmap_t population++; if (unlikely (length > max_chain_length) && occupancy * 8 > mask) - resize (mask - 8); // This ensures we jump to next larger size + alloc (mask - 8); // This ensures we jump to next larger size return true; } diff --git a/src/hb-multimap.hh b/src/hb-multimap.hh index 041562f14..0184279c1 100644 --- a/src/hb-multimap.hh +++ b/src/hb-multimap.hh @@ -81,9 +81,9 @@ struct hb_multimap_t return false; } - void resize (unsigned size) + void alloc (unsigned size) { - singulars.resize (size); + singulars.alloc (size); } protected: diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 07db3fbd5..56dd11644 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -765,7 +765,7 @@ struct CmapSubtableLongSegmented if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs)) end = start + (hb_codepoint_t) num_glyphs - gid; - mapping->resize (mapping->get_population () + end - start + 1); + mapping->alloc (mapping->get_population () + end - start + 1); for (unsigned cp = start; cp <= end; cp++) { diff --git a/src/hb-ot-post-table-v2subset.hh b/src/hb-ot-post-table-v2subset.hh index c184ad1a5..d44233610 100644 --- a/src/hb-ot-post-table-v2subset.hh +++ b/src/hb-ot-post-table-v2subset.hh @@ -80,9 +80,9 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const hb_hashmap_t glyph_name_to_new_index; - old_new_index_map.resize (num_glyphs); - old_gid_new_index_map.resize (num_glyphs); - glyph_name_to_new_index.resize (num_glyphs); + old_new_index_map.alloc (num_glyphs); + old_gid_new_index_map.alloc (num_glyphs); + glyph_name_to_new_index.alloc (num_glyphs); for (hb_codepoint_t new_gid = 0; new_gid < num_glyphs; new_gid++) { diff --git a/src/hb-subset-accelerator.hh b/src/hb-subset-accelerator.hh index c7304c0aa..9258383d2 100644 --- a/src/hb-subset-accelerator.hh +++ b/src/hb-subset-accelerator.hh @@ -92,7 +92,7 @@ struct hb_subset_accelerator_t has_seac(has_seac_), source(hb_face_reference (source)) { - gid_to_unicodes.resize (unicode_to_gid.get_population ()); + gid_to_unicodes.alloc (unicode_to_gid.get_population ()); for (const auto &_ : unicode_to_gid) { auto unicode = _.first; diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 3ef8dc2b0..6d08a5e0e 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -607,7 +607,7 @@ struct subr_remap_t : hb_inc_bimap_t * no optimization based on usage counts. fonttools doesn't appear doing that either. */ - resize (closure->get_population ()); + alloc (closure->get_population ()); for (auto old_num : *closure) add (old_num); diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 63d38da88..6a6dc03af 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -42,9 +42,9 @@ struct remap_sid_t { unsigned get_population () const { return map.get_population (); } - void resize (unsigned size) + void alloc (unsigned size) { - map.resize (size); + map.alloc (size); vector.alloc (size); } @@ -536,7 +536,7 @@ struct cff1_subset_plan auto _ = *it; bool not_is_cid = !acc.is_CID (); if (not_is_cid) - sidmap.resize (num_glyphs); + sidmap.alloc (num_glyphs); for (glyph = 1; glyph < num_glyphs; glyph++) { hb_codepoint_t old_glyph; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 26c923a17..2910ee2f6 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -561,7 +561,7 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, unicodes->get_population () < cmap_unicodes->get_population () && glyphs->get_population () < cmap_unicodes->get_population ()) { - plan->codepoint_to_glyph->resize (unicodes->get_population () + glyphs->get_population ()); + plan->codepoint_to_glyph->alloc (unicodes->get_population () + glyphs->get_population ()); auto &gid_to_unicodes = plan->accelerator->gid_to_unicodes; for (hb_codepoint_t gid : *glyphs) @@ -591,7 +591,7 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, } else { - plan->codepoint_to_glyph->resize (cmap_unicodes->get_population ()); + plan->codepoint_to_glyph->alloc (cmap_unicodes->get_population ()); for (hb_codepoint_t cp : *cmap_unicodes) { hb_codepoint_t gid = (*unicode_glyphid_map)[cp]; @@ -790,7 +790,7 @@ _create_glyph_map_gsub (const hb_set_t* glyph_set_gsub, const hb_map_t* glyph_map, hb_map_t* out) { - out->resize (glyph_set_gsub->get_population ()); + out->alloc (glyph_set_gsub->get_population ()); + hb_iter (glyph_set_gsub) | hb_map ([&] (hb_codepoint_t gid) { return hb_codepoint_pair_t (gid, glyph_map->get (gid)); @@ -810,8 +810,8 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, unsigned int *num_glyphs /* OUT */) { unsigned pop = all_gids_to_retain->get_population (); - reverse_glyph_map->resize (pop); - glyph_map->resize (pop); + reverse_glyph_map->alloc (pop); + glyph_map->alloc (pop); new_to_old_gid_list->alloc (pop); if (*requested_glyph_map)