[subset-plan] Simplify name_table_overrides allocation

This commit is contained in:
Behdad Esfahbod 2023-01-11 13:23:34 -07:00
parent 5cab4a55d2
commit 1426f1c8ea
3 changed files with 14 additions and 29 deletions

View File

@ -48,15 +48,7 @@ hb_subset_input_create_or_fail (void)
for (auto& set : input->sets_iter ()) for (auto& set : input->sets_iter ())
set = hb_set_create (); set = hb_set_create ();
#ifdef HB_EXPERIMENTAL_API if (input->in_error ())
input->name_table_overrides = hb_hashmap_create<hb_ot_name_record_ids_t, hb_bytes_t> ();
#endif
if (
#ifdef HB_EXPERIMENTAL_API
!input->name_table_overrides ||
#endif
input->in_error ())
{ {
hb_subset_input_destroy (input); hb_subset_input_destroy (input);
return nullptr; return nullptr;
@ -253,12 +245,8 @@ hb_subset_input_destroy (hb_subset_input_t *input)
hb_set_destroy (set); hb_set_destroy (set);
#ifdef HB_EXPERIMENTAL_API #ifdef HB_EXPERIMENTAL_API
if (input->name_table_overrides) for (auto _ : input->name_table_overrides)
{ _.second.fini ();
for (auto _ : *input->name_table_overrides)
_.second.fini ();
}
hb_hashmap_destroy (input->name_table_overrides);
#endif #endif
hb_free (input); hb_free (input);
@ -599,7 +587,7 @@ hb_subset_input_override_name_table (hb_subset_input_t *input,
hb_memcpy (override_name, name_str, str_len); hb_memcpy (override_name, name_str, str_len);
name_bytes = hb_bytes_t (override_name, str_len); name_bytes = hb_bytes_t (override_name, str_len);
} }
input->name_table_overrides->set (hb_ot_name_record_ids_t (platform_id, encoding_id, language_id, name_id), name_bytes); input->name_table_overrides.set (hb_ot_name_record_ids_t (platform_id, encoding_id, language_id, name_id), name_bytes);
return true; return true;
} }

View File

@ -108,7 +108,7 @@ struct hb_subset_input_t
hb_hashmap_t<hb_tag_t, float> axes_location; hb_hashmap_t<hb_tag_t, float> axes_location;
#ifdef HB_EXPERIMENTAL_API #ifdef HB_EXPERIMENTAL_API
hb_hashmap_t<hb_ot_name_record_ids_t, hb_bytes_t> *name_table_overrides; hb_hashmap_t<hb_ot_name_record_ids_t, hb_bytes_t> name_table_overrides;
#endif #endif
inline unsigned num_sets () const inline unsigned num_sets () const
@ -131,7 +131,7 @@ struct hb_subset_input_t
return axes_location.in_error () return axes_location.in_error ()
#ifdef HB_EXPERIMENTAL_API #ifdef HB_EXPERIMENTAL_API
|| name_table_overrides->in_error () || name_table_overrides.in_error ()
#endif #endif
; ;
} }

View File

@ -862,19 +862,16 @@ hb_subset_plan_create_or_fail (hb_face_t *face,
plan->pinned_at_default = true; plan->pinned_at_default = true;
#ifdef HB_EXPERIMENTAL_API #ifdef HB_EXPERIMENTAL_API
if (input->name_table_overrides) for (auto _ : input->name_table_overrides)
{ {
for (auto _ : *input->name_table_overrides) hb_bytes_t name_bytes = _.second;
{ unsigned len = name_bytes.length;
hb_bytes_t name_bytes = _.second; char *name_str = (char *) hb_malloc (len);
unsigned len = name_bytes.length; if (unlikely (!plan->check_success (name_str)))
char *name_str = (char *) hb_malloc (len); break;
if (unlikely (!plan->check_success (name_str)))
break;
hb_memcpy (name_str, name_bytes.arrayZ, len); hb_memcpy (name_str, name_bytes.arrayZ, len);
plan->name_table_overrides.set (_.first, hb_bytes_t (name_str, len)); plan->name_table_overrides.set (_.first, hb_bytes_t (name_str, len));
}
} }
#endif #endif