From e062376ef1ce0e8e303eefd3bf449c20ba1f3607 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 19 Jan 2022 17:09:34 -0700 Subject: [PATCH] [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.) --- src/hb-machinery.hh | 6 +++--- src/hb-ot-cff1-table.hh | 4 ++-- src/hb-ot-cff2-table.hh | 28 ++++++++++++++-------------- src/hb-ot-cmap-table.hh | 14 +++++++------- src/hb-ot-color-cbdt-table.hh | 4 ++-- src/hb-ot-color-sbix-table.hh | 4 ++-- src/hb-ot-color-svg-table.hh | 4 ++-- src/hb-ot-glyf-table.hh | 8 ++++---- src/hb-ot-hmtx-table.hh | 8 ++++---- src/hb-ot-layout-gdef-table.hh | 4 ++-- src/hb-ot-layout-gsubgpos.hh | 4 ++-- src/hb-ot-meta-table.hh | 4 ++-- src/hb-ot-name-table.hh | 4 ++-- src/hb-ot-post-table-v2subset.hh | 4 ++-- src/hb-ot-post-table.hh | 4 ++-- src/hb-ot-var-gvar-table.hh | 4 ++-- src/hb-subset-cff2.cc | 4 ++-- src/hb-subset-plan.cc | 16 ++++++++-------- 18 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 010c2570d..cb9ed78c1 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -244,19 +244,19 @@ struct hb_lazy_loader_t : hb_data_wrapper_t { 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); } diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index a8c0434fc..de3ed1f9b 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1270,7 +1270,7 @@ struct cff1 struct accelerator_t : accelerator_templ_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 (); diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 667ff87d0..cf99d57ca 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -397,7 +397,7 @@ struct cff2 template 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 (); 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 (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 (cff2, font->privateDictInfo.offset), font->privateDictInfo.size); - if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; } + if (unlikely (!privDictStr.sanitize (&sc))) { Xfini (); return; } dict_interpreter_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 (&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 (); diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 9b3607ac4..4253e78ec 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -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 (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 diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 963cf2ae6..33947bca9 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -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 (face); cbdt = hb_sanitize_context_t ().reference_table (face); @@ -827,7 +827,7 @@ struct CBDT upem = hb_face_get_upem (face); } - void fini () + void Xfini () { this->cblc.destroy (); this->cbdt.destroy (); diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index d2911f19e..4177cd0fd 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -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 (face); num_glyphs = face->get_num_glyphs (); } - void fini () { table.destroy (); } + void Xfini () { table.destroy (); } bool has_data () const { return table->has_data (); } diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index e022ef43b..e070796a1 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -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 (face); } - void fini () { table.destroy (); } + void Xfini () { table.destroy (); } hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const { diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 5018b5ac7..20dd69126 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -208,7 +208,7 @@ struct glyf hb_vector_t *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 (); diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 7d2d2d3eb..62e43b4cf 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -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 (face, T::variationsTag); } - void fini () + void Xfini () { table.destroy (); var_table.destroy (); diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index aea644f3e..6a2f40f3f 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -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 (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 table; }; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 25853c164..557715283 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -3846,7 +3846,7 @@ struct GSUBGPOS template struct accelerator_t { - void init (hb_face_t *face) + void Xinit (hb_face_t *face) { this->table = hb_sanitize_context_t ().reference_table (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 (); diff --git a/src/hb-ot-meta-table.hh b/src/hb-ot-meta-table.hh index e31447f8f..10f5a2f46 100644 --- a/src/hb-ot-meta-table.hh +++ b/src/hb-ot-meta-table.hh @@ -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 (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 ()); } diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 792de061a..acaabd02d 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -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 (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 (); diff --git a/src/hb-ot-post-table-v2subset.hh b/src/hb-ot-post-table-v2subset.hh index 504de2de7..d7b662a1e 100644 --- a/src/hb-ot-post-table-v2subset.hh +++ b/src/hb-ot-post-table-v2subset.hh @@ -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 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); } diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 39de67170..07cd35605 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -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 ()); diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 204fa5fc6..6541cfd59 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -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 (face); } - void fini () { table.destroy (); } + void Xfini () { table.destroy (); } private: struct x_getter { static float get (const contour_point_t &p) { return p.x; } }; diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 294267617..26e5517f2 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -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; } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 883ab8209..24b34f6ad 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -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