[subset] use anonymous union to hold the input sets instead of a map.

This commit is contained in:
Garret Rieger 2021-08-27 08:20:58 -07:00
parent 05204d7586
commit 7194c2a2a3
2 changed files with 42 additions and 30 deletions

View File

@ -45,14 +45,8 @@ hb_subset_input_create_or_fail (void)
if (unlikely (!input)) if (unlikely (!input))
return nullptr; return nullptr;
input->sets.init (); for (auto& set : input->sets_iter ())
input->sets.set (HB_SUBSET_SETS_GLYPH_INDEX, hb_set_create ()); set = 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 ());
if (input->in_error ()) if (input->in_error ())
{ {
@ -234,11 +228,9 @@ hb_subset_input_destroy (hb_subset_input_t *input)
{ {
if (!hb_object_destroy (input)) return; 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); hb_set_destroy (set);
input->sets.fini ();
hb_free (input); 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) hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type)
{ {
// TODO(garretrieger): add test for this method. // TODO(garretrieger): add test for this method.
return input->sets.get (set_type); return input->sets_iter () [set_type];
} }
/** /**

View File

@ -42,86 +42,106 @@ struct hb_subset_input_t
{ {
hb_object_header_t header; hb_object_header_t header;
hb_hashmap_t<unsigned, hb_set_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; unsigned flags;
inline unsigned num_sets () const
{
return sizeof (sets) / sizeof (hb_set_t*);
}
inline hb_array_t<hb_set_t*> sets_iter ()
{
return hb_array_t<hb_set_t*> (set_ptrs, num_sets ());
}
inline hb_set_t* unicodes() inline hb_set_t* unicodes()
{ {
return sets.get (HB_SUBSET_SETS_UNICODE); return sets.unicodes;
} }
inline const hb_set_t* unicodes() const inline const hb_set_t* unicodes() const
{ {
return sets.get (HB_SUBSET_SETS_UNICODE); return sets.unicodes;
} }
inline hb_set_t* glyphs () inline hb_set_t* glyphs ()
{ {
return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); return sets.glyphs;
} }
inline const hb_set_t* glyphs () const inline const hb_set_t* glyphs () const
{ {
return sets.get (HB_SUBSET_SETS_GLYPH_INDEX); return sets.glyphs;
} }
inline hb_set_t* name_ids () 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 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 () 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 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 () 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 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 () 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 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 () 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 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 bool in_error () const
{ {
if (sets.in_error ()) return true; for (unsigned i = 0; i < num_sets (); i++)
for (const hb_set_t* set : sets.values ())
{ {
if (unlikely (set->in_error ())) if (unlikely (set_ptrs[i]->in_error ()))
return true; return true;
} }
return false; return false;