From 1426f1c8ea29a6b71ab0f1ce9d9c79b41f407eb0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jan 2023 13:23:34 -0700 Subject: [PATCH] [subset-plan] Simplify name_table_overrides allocation --- src/hb-subset-input.cc | 20 ++++---------------- src/hb-subset-input.hh | 4 ++-- src/hb-subset-plan.cc | 19 ++++++++----------- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 664d19dbc..256fc7d45 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -48,15 +48,7 @@ hb_subset_input_create_or_fail (void) for (auto& set : input->sets_iter ()) set = hb_set_create (); -#ifdef HB_EXPERIMENTAL_API - input->name_table_overrides = hb_hashmap_create (); -#endif - - if ( -#ifdef HB_EXPERIMENTAL_API - !input->name_table_overrides || -#endif - input->in_error ()) + if (input->in_error ()) { hb_subset_input_destroy (input); return nullptr; @@ -253,12 +245,8 @@ hb_subset_input_destroy (hb_subset_input_t *input) hb_set_destroy (set); #ifdef HB_EXPERIMENTAL_API - if (input->name_table_overrides) - { - for (auto _ : *input->name_table_overrides) - _.second.fini (); - } - hb_hashmap_destroy (input->name_table_overrides); + for (auto _ : input->name_table_overrides) + _.second.fini (); #endif 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); 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; } diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 62b8c6a2d..c5ccc88be 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -108,7 +108,7 @@ struct hb_subset_input_t hb_hashmap_t axes_location; #ifdef HB_EXPERIMENTAL_API - hb_hashmap_t *name_table_overrides; + hb_hashmap_t name_table_overrides; #endif inline unsigned num_sets () const @@ -131,7 +131,7 @@ struct hb_subset_input_t return axes_location.in_error () #ifdef HB_EXPERIMENTAL_API - || name_table_overrides->in_error () + || name_table_overrides.in_error () #endif ; } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 050091708..6450d0572 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -862,19 +862,16 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->pinned_at_default = true; #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; - char *name_str = (char *) hb_malloc (len); - if (unlikely (!plan->check_success (name_str))) - break; + hb_bytes_t name_bytes = _.second; + unsigned len = name_bytes.length; + char *name_str = (char *) hb_malloc (len); + if (unlikely (!plan->check_success (name_str))) + break; - hb_memcpy (name_str, name_bytes.arrayZ, len); - plan->name_table_overrides.set (_.first, hb_bytes_t (name_str, len)); - } + hb_memcpy (name_str, name_bytes.arrayZ, len); + plan->name_table_overrides.set (_.first, hb_bytes_t (name_str, len)); } #endif