From 7194c2a2a370a39d8e41539cb7fde9a9ffed80c3 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 27 Aug 2021 08:20:58 -0700 Subject: [PATCH] [subset] use anonymous union to hold the input sets instead of a map. --- src/hb-subset-input.cc | 16 +++--------- src/hb-subset-input.hh | 56 ++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index b70c86a5b..c2b7c0492 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -45,14 +45,8 @@ hb_subset_input_create_or_fail (void) if (unlikely (!input)) return nullptr; - input->sets.init (); - input->sets.set (HB_SUBSET_SETS_GLYPH_INDEX, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_UNICODE, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_DROP_TABLE_TAG, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_NAME_ID, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_NAME_LANG_ID, hb_set_create ()); - input->sets.set (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG, hb_set_create ()); + for (auto& set : input->sets_iter ()) + set = hb_set_create (); if (input->in_error ()) { @@ -234,11 +228,9 @@ hb_subset_input_destroy (hb_subset_input_t *input) { if (!hb_object_destroy (input)) return; - for (hb_set_t* set : input->sets.values ()) + for (hb_set_t* set : input->sets_iter ()) hb_set_destroy (set); - input->sets.fini (); - hb_free (input); } @@ -361,7 +353,7 @@ HB_EXTERN hb_set_t * hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type) { // TODO(garretrieger): add test for this method. - return input->sets.get (set_type); + return input->sets_iter () [set_type]; } /** diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 82ffb6d73..0b0609128 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -42,86 +42,106 @@ struct hb_subset_input_t { hb_object_header_t header; - hb_hashmap_t sets; + union { + struct { + hb_set_t *glyphs; + hb_set_t *unicodes; + hb_set_t *no_subset_tables; + hb_set_t *drop_tables; + hb_set_t *name_ids; + hb_set_t *name_languages; + hb_set_t *layout_features; + } sets; + hb_set_t* set_ptrs[1]; + }; unsigned flags; + inline unsigned num_sets () const + { + return sizeof (sets) / sizeof (hb_set_t*); + } + + inline hb_array_t sets_iter () + { + return hb_array_t (set_ptrs, num_sets ()); + } + inline hb_set_t* unicodes() { - return sets.get (HB_SUBSET_SETS_UNICODE); + return sets.unicodes; } inline const hb_set_t* unicodes() const { - return sets.get (HB_SUBSET_SETS_UNICODE); + return sets.unicodes; } inline hb_set_t* glyphs () { - return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); + return sets.glyphs; } inline const hb_set_t* glyphs () const { - return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); + return sets.glyphs; } inline hb_set_t* name_ids () { - return sets.get (HB_SUBSET_SETS_NAME_ID); + return sets.name_ids; } inline const hb_set_t* name_ids () const { - return sets.get (HB_SUBSET_SETS_NAME_ID); + return sets.name_ids; } inline hb_set_t* name_languages () { - return sets.get (HB_SUBSET_SETS_NAME_LANG_ID); + return sets.name_languages; } inline const hb_set_t* name_languages () const { - return sets.get (HB_SUBSET_SETS_NAME_LANG_ID); + return sets.name_languages; } inline hb_set_t* no_subset_tables () { - return sets.get (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG); + return sets.no_subset_tables; } inline const hb_set_t* no_subset_tables () const { - return sets.get (HB_SUBSET_SETS_NO_SUBSET_TABLE_TAG); + return sets.no_subset_tables; } inline hb_set_t* drop_tables () { - return sets.get (HB_SUBSET_SETS_DROP_TABLE_TAG); + return sets.drop_tables; } inline const hb_set_t* drop_tables () const { - return sets.get (HB_SUBSET_SETS_DROP_TABLE_TAG); + return sets.drop_tables; } inline hb_set_t* layout_features () { - return sets.get (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + return sets.layout_features; } inline const hb_set_t* layout_features () const { - return sets.get (HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + return sets.layout_features; } bool in_error () const { - if (sets.in_error ()) return true; - for (const hb_set_t* set : sets.values ()) + for (unsigned i = 0; i < num_sets (); i++) { - if (unlikely (set->in_error ())) + if (unlikely (set_ptrs[i]->in_error ())) return true; } return false;