[machinery] Make accelerator lazy-loader call Xinit/Xfini

Instead of init/fini. To isolate those functions. To be turned into
constructor/destructors, ideally one per commit (after some SFINAE
foo.)
This commit is contained in:
Behdad Esfahbod 2022-01-19 17:09:34 -07:00
parent 1522015bb2
commit e062376ef1
18 changed files with 64 additions and 64 deletions

View File

@ -244,19 +244,19 @@ struct hb_lazy_loader_t : hb_data_wrapper_t<Data, WheresData>
{
Stored *p = (Stored *) hb_calloc (1, sizeof (Stored));
if (likely (p))
p->init (data);
p->Xinit (data);
return p;
}
static Stored *create ()
{
Stored *p = (Stored *) hb_calloc (1, sizeof (Stored));
if (likely (p))
p->init ();
p->Xinit ();
return p;
}
static void destroy (Stored *p)
{
p->fini ();
p->Xfini ();
hb_free (p);
}

View File

@ -1270,7 +1270,7 @@ struct cff1
struct accelerator_t : accelerator_templ_t<cff1_private_dict_opset_t, cff1_private_dict_values_t>
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
SUPER::init (face);
@ -1296,7 +1296,7 @@ struct cff1
glyph_names.qsort ();
}
void fini ()
void Xfini ()
{
glyph_names.fini ();

View File

@ -397,7 +397,7 @@ struct cff2
template <typename PRIVOPSET, typename PRIVDICTVAL>
struct accelerator_templ_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
topDict.init ();
fontDicts.init ();
@ -412,15 +412,15 @@ struct cff2
const OT::cff2 *cff2 = this->blob->template as<OT::cff2> ();
if (cff2 == &Null (OT::cff2))
{ fini (); return; }
{ Xfini (); return; }
{ /* parse top dict */
byte_str_t topDictStr (cff2 + cff2->topDict, cff2->topDictSize);
if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; }
if (unlikely (!topDictStr.sanitize (&sc))) { Xfini (); return; }
cff2_top_dict_interpreter_t top_interp;
top_interp.env.init (topDictStr);
topDict.init ();
if (unlikely (!top_interp.interpret (topDict))) { fini (); return; }
if (unlikely (!top_interp.interpret (topDict))) { Xfini (); return; }
}
globalSubrs = &StructAtOffset<CFF2Subrs> (cff2, cff2->topDict + cff2->topDictSize);
@ -434,44 +434,44 @@ struct cff2
(globalSubrs == &Null (CFF2Subrs)) || unlikely (!globalSubrs->sanitize (&sc)) ||
(fdArray == &Null (CFF2FDArray)) || unlikely (!fdArray->sanitize (&sc)) ||
(((fdSelect != &Null (CFF2FDSelect)) && unlikely (!fdSelect->sanitize (&sc, fdArray->count)))))
{ fini (); return; }
{ Xfini (); return; }
num_glyphs = charStrings->count;
if (num_glyphs != sc.get_num_glyphs ())
{ fini (); return; }
{ Xfini (); return; }
fdCount = fdArray->count;
if (!privateDicts.resize (fdCount))
{ fini (); return; }
{ Xfini (); return; }
/* parse font dicts and gather private dicts */
for (unsigned int i = 0; i < fdCount; i++)
{
const byte_str_t fontDictStr = (*fdArray)[i];
if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; }
if (unlikely (!fontDictStr.sanitize (&sc))) { Xfini (); return; }
cff2_font_dict_values_t *font;
cff2_font_dict_interpreter_t font_interp;
font_interp.env.init (fontDictStr);
font = fontDicts.push ();
if (unlikely (font == &Crap (cff2_font_dict_values_t))) { fini (); return; }
if (unlikely (font == &Crap (cff2_font_dict_values_t))) { Xfini (); return; }
font->init ();
if (unlikely (!font_interp.interpret (*font))) { fini (); return; }
if (unlikely (!font_interp.interpret (*font))) { Xfini (); return; }
const byte_str_t privDictStr (StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset), font->privateDictInfo.size);
if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; }
if (unlikely (!privDictStr.sanitize (&sc))) { Xfini (); return; }
dict_interpreter_t<PRIVOPSET, PRIVDICTVAL, cff2_priv_dict_interp_env_t> priv_interp;
priv_interp.env.init(privDictStr);
privateDicts[i].init ();
if (unlikely (!priv_interp.interpret (privateDicts[i]))) { fini (); return; }
if (unlikely (!priv_interp.interpret (privateDicts[i]))) { Xfini (); return; }
privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (&privDictStr[0], privateDicts[i].subrsOffset);
if (privateDicts[i].localSubrs != &Null (CFF2Subrs) &&
unlikely (!privateDicts[i].localSubrs->sanitize (&sc)))
{ fini (); return; }
{ Xfini (); return; }
}
}
void fini ()
void Xfini ()
{
sc.end_processing ();
topDict.fini ();

View File

@ -368,10 +368,10 @@ struct CmapSubtableFormat4
struct accelerator_t
{
accelerator_t () {}
accelerator_t (const CmapSubtableFormat4 *subtable) { init (subtable); }
~accelerator_t () { fini (); }
accelerator_t (const CmapSubtableFormat4 *subtable) { Xinit (subtable); }
~accelerator_t () { Xfini (); }
void init (const CmapSubtableFormat4 *subtable)
void Xinit (const CmapSubtableFormat4 *subtable)
{
segCount = subtable->segCountX2 / 2;
endCount = subtable->values.arrayZ;
@ -381,7 +381,7 @@ struct CmapSubtableFormat4
glyphIdArray = idRangeOffset + segCount;
glyphIdArrayLength = (subtable->length - 16 - 8 * segCount) / 2;
}
void fini () {}
void Xfini () {}
bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const
{
@ -1665,7 +1665,7 @@ struct cmap
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
this->table = hb_sanitize_context_t ().reference_table<cmap> (face);
bool symbol;
@ -1692,7 +1692,7 @@ struct cmap
break;
case 4:
{
this->format4_accel.init (&subtable->u.format4);
this->format4_accel.Xinit (&subtable->u.format4);
this->get_glyph_data = &this->format4_accel;
this->get_glyph_funcZ = this->format4_accel.get_glyph_func;
break;
@ -1701,7 +1701,7 @@ struct cmap
}
}
void fini () { this->table.destroy (); }
void Xfini () { this->table.destroy (); }
bool get_nominal_glyph (hb_codepoint_t unicode,
hb_codepoint_t *glyph) const

View File

@ -819,7 +819,7 @@ struct CBDT
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
cblc = hb_sanitize_context_t ().reference_table<CBLC> (face);
cbdt = hb_sanitize_context_t ().reference_table<CBDT> (face);
@ -827,7 +827,7 @@ struct CBDT
upem = hb_face_get_upem (face);
}
void fini ()
void Xfini ()
{
this->cblc.destroy ();
this->cbdt.destroy ();

View File

@ -202,12 +202,12 @@ struct sbix
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
table = hb_sanitize_context_t ().reference_table<sbix> (face);
num_glyphs = face->get_num_glyphs ();
}
void fini () { table.destroy (); }
void Xfini () { table.destroy (); }
bool has_data () const { return table->has_data (); }

View File

@ -79,9 +79,9 @@ struct SVG
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{ table = hb_sanitize_context_t ().reference_table<SVG> (face); }
void fini () { table.destroy (); }
void Xfini () { table.destroy (); }
hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const
{

View File

@ -208,7 +208,7 @@ struct glyf
hb_vector_t<SubsetGlyph> *glyphs /* OUT */) const
{
OT::glyf::accelerator_t glyf;
glyf.init (plan->source);
glyf.Xinit (plan->source);
+ hb_range (plan->num_output_glyphs ())
| hb_map ([&] (hb_codepoint_t new_gid)
@ -234,7 +234,7 @@ struct glyf
| hb_sink (glyphs)
;
glyf.fini ();
glyf.Xfini ();
}
static bool
@ -920,7 +920,7 @@ struct glyf
struct accelerator_t
{
void init (hb_face_t *face_)
void Xinit (hb_face_t *face_)
{
short_offset = false;
num_glyphs = 0;
@ -954,7 +954,7 @@ struct glyf
num_glyphs = hb_min (num_glyphs, face->get_num_glyphs ());
}
void fini ()
void Xfini ()
{
loca_table.destroy ();
glyf_table.destroy ();

View File

@ -128,7 +128,7 @@ struct hmtxvmtx
if (unlikely (!table_prime)) return_trace (false);
accelerator_t _mtx;
_mtx.init (c->plan->source);
_mtx.Xinit (c->plan->source);
unsigned num_advances = _mtx.num_advances_for_subset (c->plan);
auto it =
@ -144,7 +144,7 @@ struct hmtxvmtx
table_prime->serialize (c->serializer, it, num_advances);
_mtx.fini ();
_mtx.Xfini ();
if (unlikely (c->serializer->in_error ()))
return_trace (false);
@ -160,7 +160,7 @@ struct hmtxvmtx
{
friend struct hmtxvmtx;
void init (hb_face_t *face,
void Xinit (hb_face_t *face,
unsigned int default_advance_ = 0)
{
default_advance = default_advance_ ? default_advance_ : hb_face_get_upem (face);
@ -194,7 +194,7 @@ struct hmtxvmtx
var_table = hb_sanitize_context_t ().reference_table<HVARVVAR> (face, T::variationsTag);
}
void fini ()
void Xfini ()
{
table.destroy ();
var_table.destroy ();

View File

@ -585,7 +585,7 @@ struct GDEF
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
this->table = hb_sanitize_context_t ().reference_table<GDEF> (face);
if (unlikely (this->table->is_blocklisted (this->table.get_blob (), face)))
@ -595,7 +595,7 @@ struct GDEF
}
}
void fini () { this->table.destroy (); }
void Xfini () { this->table.destroy (); }
hb_blob_ptr_t<GDEF> table;
};

View File

@ -3846,7 +3846,7 @@ struct GSUBGPOS
template <typename T>
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
this->table = hb_sanitize_context_t ().reference_table<T> (face);
if (unlikely (this->table->is_blocklisted (this->table.get_blob (), face)))
@ -3869,7 +3869,7 @@ struct GSUBGPOS
this->accels[i].init (table->get_lookup (i));
}
void fini ()
void Xfini ()
{
for (unsigned int i = 0; i < this->lookup_count; i++)
this->accels[i].fini ();

View File

@ -71,9 +71,9 @@ struct meta
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{ table = hb_sanitize_context_t ().reference_table<meta> (face); }
void fini () { table.destroy (); }
void Xfini () { table.destroy (); }
hb_blob_t *reference_entry (hb_tag_t tag) const
{ return table->dataMaps.lsearch (tag).reference_entry (table.get_blob ()); }

View File

@ -279,7 +279,7 @@ struct name
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
this->table = hb_sanitize_context_t ().reference_table<name> (face);
assert (this->table.get_length () >= this->table->stringOffset);
@ -319,7 +319,7 @@ struct name
this->names.resize (j);
}
void fini ()
void Xfini ()
{
this->names.fini ();
this->table.destroy ();

View File

@ -77,7 +77,7 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const
unsigned i = 0;
post::accelerator_t _post;
_post.init (c->plan->source);
_post.Xinit (c->plan->source);
hb_hashmap_t<hb_bytes_t, unsigned, std::nullptr_t, unsigned, nullptr, (unsigned)-1> glyph_name_to_new_index;
for (hb_codepoint_t new_gid = 0; new_gid < num_glyphs; new_gid++)
@ -129,7 +129,7 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const
;
bool ret = serialize (c->serializer, index_iter, &_post);
_post.fini ();
_post.Xfini ();
return_trace (ret);
}

View File

@ -111,7 +111,7 @@ struct post
struct accelerator_t
{
friend struct postV2Tail;
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{
index_to_offset.init ();
@ -132,7 +132,7 @@ struct post
data += 1 + *data)
index_to_offset.push (data - pool);
}
void fini ()
void Xfini ()
{
index_to_offset.fini ();
hb_free (gids_sorted_by_name.get ());

View File

@ -498,9 +498,9 @@ struct gvar
public:
struct accelerator_t
{
void init (hb_face_t *face)
void Xinit (hb_face_t *face)
{ table = hb_sanitize_context_t ().reference_table<gvar> (face); }
void fini () { table.destroy (); }
void Xfini () { table.destroy (); }
private:
struct x_getter { static float get (const contour_point_t &p) { return p.x; } };

View File

@ -451,9 +451,9 @@ bool
hb_subset_cff2 (hb_subset_context_t *c)
{
OT::cff2::accelerator_subset_t acc;
acc.init (c->plan->source);
acc.Xinit (c->plan->source);
bool result = likely (acc.is_valid ()) && _hb_subset_cff2 (acc, c);
acc.fini ();
acc.Xfini ();
return result;
}

View File

@ -229,9 +229,9 @@ _cmap_closure (hb_face_t *face,
hb_set_t *glyphset)
{
OT::cmap::accelerator_t cmap;
cmap.init (face);
cmap.Xinit (face);
cmap.table->closure_glyphs (unicodes, glyphset);
cmap.fini ();
cmap.Xfini ();
}
static void _colr_closure (hb_face_t *face,
@ -295,7 +295,7 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes,
hb_subset_plan_t *plan)
{
OT::cmap::accelerator_t cmap;
cmap.init (plan->source);
cmap.Xinit (plan->source);
constexpr static const int size_threshold = 4096;
@ -344,7 +344,7 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes,
+ plan->codepoint_to_glyph->keys () | hb_sink (plan->unicodes);
+ plan->codepoint_to_glyph->values () | hb_sink (plan->_glyphset_gsub);
cmap.fini ();
cmap.Xfini ();
}
static void
@ -357,9 +357,9 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
#ifndef HB_NO_SUBSET_CFF
OT::cff1::accelerator_t cff;
#endif
glyf.init (plan->source);
glyf.Xinit (plan->source);
#ifndef HB_NO_SUBSET_CFF
cff.init (plan->source);
cff.Xinit (plan->source);
#endif
plan->_glyphset_gsub->add (0); // Not-def
@ -421,9 +421,9 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
#endif
#ifndef HB_NO_SUBSET_CFF
cff.fini ();
cff.Xfini ();
#endif
glyf.fini ();
glyf.Xfini ();
}
static void