[subset-cff] Convert subr_closures_t to constructor/destructor instead of init/fini.

This commit is contained in:
Garret Rieger 2022-01-18 10:29:04 -08:00
parent a48aa9850a
commit f1dc8b087c
1 changed files with 13 additions and 37 deletions

View File

@ -275,45 +275,24 @@ struct subr_flattener_t
struct subr_closures_t struct subr_closures_t
{ {
subr_closures_t () : valid (false), global_closure (nullptr) subr_closures_t (unsigned int fd_count) : valid (false), global_closure (), local_closures ()
{ local_closures.init (); }
void init (unsigned int fd_count)
{ {
valid = true; valid = true;
global_closure = hb_set_create ();
if (global_closure == hb_set_get_empty ())
valid = false;
if (!local_closures.resize (fd_count)) if (!local_closures.resize (fd_count))
valid = false; valid = false;
for (unsigned int i = 0; i < local_closures.length; i++)
{
local_closures[i] = hb_set_create ();
if (local_closures[i] == hb_set_get_empty ())
valid = false;
}
}
void fini ()
{
hb_set_destroy (global_closure);
for (unsigned int i = 0; i < local_closures.length; i++)
hb_set_destroy (local_closures[i]);
local_closures.fini ();
} }
void reset () void reset ()
{ {
hb_set_clear (global_closure); global_closure.clear();
for (unsigned int i = 0; i < local_closures.length; i++) for (unsigned int i = 0; i < local_closures.length; i++)
hb_set_clear (local_closures[i]); local_closures[i].clear();
} }
bool is_valid () const { return valid; } bool is_valid () const { return valid; }
bool valid; bool valid;
hb_set_t *global_closure; hb_set_t global_closure;
hb_vector_t<hb_set_t *> local_closures; hb_vector_t<hb_set_t> local_closures;
}; };
struct parsed_cs_op_t : op_str_t struct parsed_cs_op_t : op_str_t
@ -486,7 +465,7 @@ struct subr_subset_param_t
struct subr_remap_t : hb_inc_bimap_t struct subr_remap_t : hb_inc_bimap_t
{ {
void create (hb_set_t *closure) void create (const hb_set_t *closure)
{ {
/* create a remapping of subroutine numbers from old to new. /* create a remapping of subroutine numbers from old to new.
* no optimization based on usage counts. fonttools doesn't appear doing that either. * no optimization based on usage counts. fonttools doesn't appear doing that either.
@ -516,7 +495,7 @@ struct subr_remap_t : hb_inc_bimap_t
struct subr_remaps_t struct subr_remaps_t
{ {
void init (unsigned int fdCount) subr_remaps_t (unsigned int fdCount)
{ {
local_remaps.resize (fdCount); local_remaps.resize (fdCount);
} }
@ -528,9 +507,9 @@ struct subr_remaps_t
void create (subr_closures_t& closures) void create (subr_closures_t& closures)
{ {
global_remap.create (closures.global_closure); global_remap.create (&closures.global_closure);
for (unsigned int i = 0; i < local_remaps.length; i++) for (unsigned int i = 0; i < local_remaps.length; i++)
local_remaps[i].create (closures.local_closures[i]); local_remaps[i].create (&closures.local_closures[i]);
} }
subr_remap_t global_remap; subr_remap_t global_remap;
@ -541,7 +520,7 @@ template <typename SUBSETTER, typename SUBRS, typename ACC, typename ENV, typena
struct subr_subsetter_t struct subr_subsetter_t
{ {
subr_subsetter_t (ACC &acc_, const hb_subset_plan_t *plan_) subr_subsetter_t (ACC &acc_, const hb_subset_plan_t *plan_)
: acc (acc_), plan (plan_) : acc (acc_), plan (plan_), closures(acc_.fdCount), remaps(acc_.fdCount)
{} {}
/* Subroutine subsetting with --no-desubroutinize runs in phases: /* Subroutine subsetting with --no-desubroutinize runs in phases:
@ -560,9 +539,6 @@ struct subr_subsetter_t
*/ */
bool subset (void) bool subset (void)
{ {
closures.init (acc.fdCount);
remaps.init (acc.fdCount);
parsed_charstrings.resize (plan->num_output_glyphs ()); parsed_charstrings.resize (plan->num_output_glyphs ());
parsed_global_subrs.resize (acc.globalSubrs->count); parsed_global_subrs.resize (acc.globalSubrs->count);
@ -599,7 +575,7 @@ struct subr_subsetter_t
subr_subset_param_t param; subr_subset_param_t param;
param.init (&parsed_charstrings[i], param.init (&parsed_charstrings[i],
&parsed_global_subrs, &parsed_local_subrs[fd], &parsed_global_subrs, &parsed_local_subrs[fd],
closures.global_closure, closures.local_closures[fd], &closures.global_closure, &closures.local_closures[fd],
plan->flags & HB_SUBSET_FLAGS_NO_HINTING); plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
if (unlikely (!interp.interpret (param))) if (unlikely (!interp.interpret (param)))
@ -623,7 +599,7 @@ struct subr_subsetter_t
subr_subset_param_t param; subr_subset_param_t param;
param.init (&parsed_charstrings[i], param.init (&parsed_charstrings[i],
&parsed_global_subrs, &parsed_local_subrs[fd], &parsed_global_subrs, &parsed_local_subrs[fd],
closures.global_closure, closures.local_closures[fd], &closures.global_closure, &closures.local_closures[fd],
plan->flags & HB_SUBSET_FLAGS_NO_HINTING); plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
drop_hints_param_t drop; drop_hints_param_t drop;
@ -648,7 +624,7 @@ struct subr_subsetter_t
subr_subset_param_t param; subr_subset_param_t param;
param.init (&parsed_charstrings[i], param.init (&parsed_charstrings[i],
&parsed_global_subrs, &parsed_local_subrs[fd], &parsed_global_subrs, &parsed_local_subrs[fd],
closures.global_closure, closures.local_closures[fd], &closures.global_closure, &closures.local_closures[fd],
plan->flags & HB_SUBSET_FLAGS_NO_HINTING); plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
collect_subr_refs_in_str (parsed_charstrings[i], param); collect_subr_refs_in_str (parsed_charstrings[i], param);
} }