[subset-accelerator] Streamline constructor/destructor

This commit is contained in:
Behdad Esfahbod 2023-01-12 14:46:44 -07:00
parent c4c646280f
commit 8e71f7e8ed
1 changed files with 34 additions and 18 deletions

View File

@ -56,37 +56,53 @@ struct hb_subset_accelerator_t
const hb_set_t& unicodes_, const hb_set_t& unicodes_,
bool has_seac_) { bool has_seac_) {
hb_subset_accelerator_t* accel = hb_subset_accelerator_t* accel =
(hb_subset_accelerator_t*) hb_malloc (sizeof(hb_subset_accelerator_t)); (hb_subset_accelerator_t*) hb_calloc (1, sizeof(hb_subset_accelerator_t));
new (accel) hb_subset_accelerator_t (unicode_to_gid_, gid_to_unicodes_, unicodes_);
accel->has_seac = has_seac_; new (accel) hb_subset_accelerator_t (unicode_to_gid_,
gid_to_unicodes_,
unicodes_,
has_seac_);
return accel; return accel;
} }
static void destroy(void* value) { static void destroy (void* p)
if (!value) return; {
if (!p) return;
hb_subset_accelerator_t* accel = (hb_subset_accelerator_t*) value; hb_subset_accelerator_t *accel = (hb_subset_accelerator_t *) p;
if (accel->cff_accelerator && accel->destroy_cff_accelerator)
accel->destroy_cff_accelerator ((void*) accel->cff_accelerator);
if (accel->cmap_cache && accel->destroy_cmap_cache)
accel->destroy_cmap_cache ((void*) accel->cmap_cache);
accel->~hb_subset_accelerator_t (); accel->~hb_subset_accelerator_t ();
hb_free (accel); hb_free (accel);
} }
hb_subset_accelerator_t (const hb_map_t& unicode_to_gid_, hb_subset_accelerator_t (const hb_map_t& unicode_to_gid_,
const hb_multimap_t& gid_to_unicodes_, const hb_multimap_t& gid_to_unicodes_,
const hb_set_t& unicodes_) const hb_set_t& unicodes_,
: unicode_to_gid(unicode_to_gid_), gid_to_unicodes (gid_to_unicodes_), unicodes(unicodes_), bool has_seac_) :
cmap_cache(nullptr), destroy_cmap_cache(nullptr), unicode_to_gid(unicode_to_gid_),
has_seac(false), cff_accelerator(nullptr), destroy_cff_accelerator(nullptr) gid_to_unicodes (gid_to_unicodes_),
{ sanitized_table_cache_lock.init (); } unicodes(unicodes_),
cmap_cache(nullptr),
destroy_cmap_cache(nullptr),
has_seac(has_seac_),
cff_accelerator(nullptr),
destroy_cff_accelerator(nullptr)
{
sanitized_table_cache_lock.init ();
}
~hb_subset_accelerator_t () ~hb_subset_accelerator_t ()
{ sanitized_table_cache_lock.fini (); } {
if (cff_accelerator && destroy_cff_accelerator)
destroy_cff_accelerator ((void*) cff_accelerator);
if (cmap_cache && destroy_cmap_cache)
destroy_cmap_cache ((void*) cmap_cache);
sanitized_table_cache_lock.fini ();
}
// Generic // Generic