[map] Rename resize() to alloc()

Better matches the functionality, and hb_vector_t.
pull/4299/head
Behdad Esfahbod 2 years ago
parent 793f663bad
commit 393f0f9f16
  1. 10
      src/hb-bimap.hh
  2. 12
      src/hb-map.hh
  3. 4
      src/hb-multimap.hh
  4. 2
      src/hb-ot-cmap-table.hh
  5. 6
      src/hb-ot-post-table-v2subset.hh
  6. 2
      src/hb-subset-accelerator.hh
  7. 2
      src/hb-subset-cff-common.hh
  8. 6
      src/hb-subset-cff1.cc
  9. 10
      src/hb-subset-plan.cc

@ -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 <hb_codepoint_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);

@ -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<hb_pair_t<K, V>> 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;
}

@ -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:

@ -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++)
{

@ -80,9 +80,9 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const
hb_hashmap_t<hb_bytes_t, uint32_t, true> 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++)
{

@ -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;

@ -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);

@ -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;

@ -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)

Loading…
Cancel
Save