src/hb-glib.cc | 36 +++++++++++++++++++++----- src/hb-icu.cc | 51 ++++++++++++++++++++++++++----------- src/hb-open-type-private.hh | 10 ++++--- src/hb-ot-layout.cc | 3 ++ src/hb-ot-shape-complex-arabic.cc | 1 src/hb-ot-shape-complex-default.cc | 1 src/hb-ot-shape-complex-hangul.cc | 1 src/hb-ot-shape-complex-hebrew.cc | 1 src/hb-ot-shape-complex-indic.cc | 1 src/hb-ot-shape-complex-myanmar.cc | 2 - src/hb-ot-shape-complex-private.hh | 2 - src/hb-ot-shape-complex-thai.cc | 1 src/hb-ot-shape-complex-tibetan.cc | 1 src/hb-ot-shape-complex-use.cc | 1 src/hb-private.hh | 2 - src/hb-ucdn.cc | 37 +++++++++++++++++++++----- src/main.cc | 1 17 files changed, 106 insertions(+), 46 deletions(-)
New commits: commit 8864864b624590d95ae5dca61956695cbff1269a Author: Behdad Esfahbod <[email protected]> Date: Fri Oct 27 15:26:45 2017 -0600 [glib/icu/ucdn] Make the funcs object allocated on demand diff --git a/src/hb-glib.cc b/src/hb-glib.cc index 5b0a1eb3..c8863ea7 100644 --- a/src/hb-glib.cc +++ b/src/hb-glib.cc @@ -364,22 +364,44 @@ hb_glib_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs HB_UNUSED, return utf8_decomposed_len; } +static hb_unicode_funcs_t *static_glib_funcs = nullptr; + +#ifdef HB_USE_ATEXIT +static +void free_static_glib_funcs (void) +{ + hb_unicode_funcs_destroy (static_glib_funcs); +} +#endif + hb_unicode_funcs_t * hb_glib_get_unicode_funcs (void) { - static const hb_unicode_funcs_t _hb_glib_unicode_funcs = { - HB_OBJECT_HEADER_STATIC, +retry: + hb_unicode_funcs_t *funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_glib_funcs); - nullptr, /* parent */ - true, /* immutable */ - { -#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_glib_unicode_##name, + if (unlikely (!funcs)) + { + funcs = hb_unicode_funcs_create (nullptr); + +#define HB_UNICODE_FUNC_IMPLEMENT(name) \ + hb_unicode_funcs_set_##name##_func (funcs, hb_glib_unicode_##name, nullptr, nullptr); HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS #undef HB_UNICODE_FUNC_IMPLEMENT + + hb_unicode_funcs_make_immutable (funcs); + + if (!hb_atomic_ptr_cmpexch (&static_glib_funcs, nullptr, funcs)) { + hb_unicode_funcs_destroy (funcs); + goto retry; } + +#ifdef HB_USE_ATEXIT + atexit (free_static_glib_funcs); /* First person registers atexit() callback. */ +#endif }; - return const_cast<hb_unicode_funcs_t *> (&_hb_glib_unicode_funcs); + return funcs; } #if GLIB_CHECK_VERSION(2,31,10) diff --git a/src/hb-icu.cc b/src/hb-icu.cc index 01d15f48..2550e438 100644 --- a/src/hb-icu.cc +++ b/src/hb-icu.cc @@ -345,27 +345,50 @@ hb_icu_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs HB_UNUSED, } +static hb_unicode_funcs_t *static_icu_funcs = nullptr; + +#ifdef HB_USE_ATEXIT +static +void free_static_icu_funcs (void) +{ + hb_unicode_funcs_destroy (static_icu_funcs); +} +#endif + hb_unicode_funcs_t * hb_icu_get_unicode_funcs (void) { - static const hb_unicode_funcs_t _hb_icu_unicode_funcs = { - HB_OBJECT_HEADER_STATIC, +retry: + hb_unicode_funcs_t *funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_icu_funcs); + + if (unlikely (!funcs)) + { +#if U_ICU_VERSION_MAJOR_NUM >= 49 + if (!hb_atomic_ptr_get (&normalizer)) { + UErrorCode icu_err = U_ZERO_ERROR; + /* We ignore failure in getNFCInstace(). */ + (void) hb_atomic_ptr_cmpexch (&normalizer, nullptr, unorm2_getNFCInstance (&icu_err)); + } +#endif - nullptr, /* parent */ - true, /* immutable */ - { -#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_icu_unicode_##name, + funcs = hb_unicode_funcs_create (nullptr); + +#define HB_UNICODE_FUNC_IMPLEMENT(name) \ + hb_unicode_funcs_set_##name##_func (funcs, hb_icu_unicode_##name, nullptr, nullptr); HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS #undef HB_UNICODE_FUNC_IMPLEMENT + + hb_unicode_funcs_make_immutable (funcs); + + if (!hb_atomic_ptr_cmpexch (&static_icu_funcs, nullptr, funcs)) { + hb_unicode_funcs_destroy (funcs); + goto retry; } - }; -#if U_ICU_VERSION_MAJOR_NUM >= 49 - if (!hb_atomic_ptr_get (&normalizer)) { - UErrorCode icu_err = U_ZERO_ERROR; - /* We ignore failure in getNFCInstace(). */ - (void) hb_atomic_ptr_cmpexch (&normalizer, nullptr, unorm2_getNFCInstance (&icu_err)); - } +#ifdef HB_USE_ATEXIT + atexit (free_static_icu_funcs); /* First person registers atexit() callback. */ #endif - return const_cast<hb_unicode_funcs_t *> (&_hb_icu_unicode_funcs); + }; + + return funcs; } diff --git a/src/hb-ucdn.cc b/src/hb-ucdn.cc index c237ee82..e51f0353 100644 --- a/src/hb-ucdn.cc +++ b/src/hb-ucdn.cc @@ -231,22 +231,43 @@ hb_ucdn_decompose_compatibility(hb_unicode_funcs_t *ufuncs HB_UNUSED, return ucdn_compat_decompose(u, decomposed); } +static hb_unicode_funcs_t *static_ucdn_funcs = nullptr; + +#ifdef HB_USE_ATEXIT +static +void free_static_ucdn_funcs (void) +{ + hb_unicode_funcs_destroy (static_ucdn_funcs); +} +#endif + extern "C" HB_INTERNAL hb_unicode_funcs_t * hb_ucdn_get_unicode_funcs (void) { - static const hb_unicode_funcs_t _hb_ucdn_unicode_funcs = { - HB_OBJECT_HEADER_STATIC, +retry: + hb_unicode_funcs_t *funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_ucdn_funcs); + + if (unlikely (!funcs)) + { + funcs = hb_unicode_funcs_create (nullptr); - nullptr, /* parent */ - true, /* immutable */ - { -#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_ucdn_##name, +#define HB_UNICODE_FUNC_IMPLEMENT(name) \ + hb_unicode_funcs_set_##name##_func (funcs, hb_ucdn_##name, nullptr, nullptr); HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS #undef HB_UNICODE_FUNC_IMPLEMENT + + hb_unicode_funcs_make_immutable (funcs); + + if (!hb_atomic_ptr_cmpexch (&static_ucdn_funcs, nullptr, funcs)) { + hb_unicode_funcs_destroy (funcs); + goto retry; } + +#ifdef HB_USE_ATEXIT + atexit (free_static_ucdn_funcs); /* First person registers atexit() callback. */ +#endif }; - return const_cast<hb_unicode_funcs_t *> (&_hb_ucdn_unicode_funcs); + return funcs; } - commit af3f72f9eb7d7b80ea827976a3303390b5deae8d Author: Behdad Esfahbod <[email protected]> Date: Fri Oct 27 15:13:50 2017 -0600 Correctly mark NullPool const Saves some more code size as well! diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index f1c90474..a49071d2 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -133,7 +133,7 @@ static inline Type& StructAfter(TObject &X) #define HB_NULL_POOL_SIZE 264 static_assert (HB_NULL_POOL_SIZE % sizeof (void *) == 0, "Align HB_NULL_POOL_SIZE."); -extern HB_INTERNAL const void *_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; +extern HB_INTERNAL const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; /* Generic nul-content Null objects. */ template <typename Type> diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 4850f720..df43c29e 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -39,7 +39,7 @@ #include "hb-ot-map-private.hh" -const void *OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; +const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; hb_ot_layout_t * diff --git a/src/main.cc b/src/main.cc index eb1711ed..377d1396 100644 --- a/src/main.cc +++ b/src/main.cc @@ -38,7 +38,7 @@ using namespace OT; -const void *OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; +const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; int main (int argc, char **argv) commit 51f4d4d5cd5a0dd1a581bee5b55b3cc0a74cbea3 Author: Behdad Esfahbod <[email protected]> Date: Fri Oct 27 15:09:22 2017 -0600 Reduce prealloced number of user-data items from 2 to 1 Even 1 is too many but putting 0 breaks compile. Saves 3k in .so diff --git a/src/hb-private.hh b/src/hb-private.hh index a6b3ab8c..ab6511dc 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -545,7 +545,7 @@ struct hb_auto_array_t : hb_prealloced_array_t <Type> template <typename item_t, typename lock_t> struct hb_lockable_set_t { - hb_prealloced_array_t <item_t, 2> items; + hb_prealloced_array_t <item_t, 1> items; inline void init (void) { items.init (); } commit 3205de7906abab9d12e614e86e2c182a41420698 Author: Behdad Esfahbod <[email protected]> Date: Fri Oct 27 15:01:40 2017 -0600 Make the NullPool HB_INTERNAL shared Saves 2k of .bss section. diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index f0ff2ff5..f1c90474 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -130,14 +130,16 @@ static inline Type& StructAfter(TObject &X) */ /* Global nul-content Null pool. Enlarge as necessary. */ -/* TODO This really should be a extern HB_INTERNAL and defined somewhere... */ -static const void *_NullPool[(256+8) / sizeof (void *)]; + +#define HB_NULL_POOL_SIZE 264 +static_assert (HB_NULL_POOL_SIZE % sizeof (void *) == 0, "Align HB_NULL_POOL_SIZE."); +extern HB_INTERNAL const void *_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; /* Generic nul-content Null objects. */ template <typename Type> static inline const Type& Null (void) { - static_assert ((sizeof (Type) <= sizeof (_NullPool)), ""); - return *CastP<Type> (_NullPool); + static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); + return *CastP<Type> (_hb_NullPool); } /* Specializaiton for arbitrary-content arbitrary-sized Null objects. */ diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 71e78268..4850f720 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -39,6 +39,9 @@ #include "hb-ot-map-private.hh" +const void *OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; + + hb_ot_layout_t * _hb_ot_layout_create (hb_face_t *face) { diff --git a/src/main.cc b/src/main.cc index 93c3b46a..eb1711ed 100644 --- a/src/main.cc +++ b/src/main.cc @@ -38,6 +38,7 @@ using namespace OT; +const void *OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]; int main (int argc, char **argv) commit 7036f1d22c4001b79d3205c16aac3fefbfcaae24 Author: Behdad Esfahbod <[email protected]> Date: Fri Oct 27 14:42:59 2017 -0600 [ot] Remove shaper name In ten years we never used them... diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc index 4a92d410..a303fc13 100644 --- a/src/hb-ot-shape-complex-arabic.cc +++ b/src/hb-ot-shape-complex-arabic.cc @@ -689,7 +689,6 @@ reorder_marks_arabic (const hb_ot_shape_plan_t *plan, const hb_ot_complex_shaper_t _hb_ot_complex_shaper_arabic = { - "arabic", collect_features_arabic, nullptr, /* override_features */ data_create_arabic, diff --git a/src/hb-ot-shape-complex-default.cc b/src/hb-ot-shape-complex-default.cc index 99b53a5a..68a62a10 100644 --- a/src/hb-ot-shape-complex-default.cc +++ b/src/hb-ot-shape-complex-default.cc @@ -29,7 +29,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_default = { - "default", nullptr, /* collect_features */ nullptr, /* override_features */ nullptr, /* data_create */ diff --git a/src/hb-ot-shape-complex-hangul.cc b/src/hb-ot-shape-complex-hangul.cc index 0f3337ff..7508c223 100644 --- a/src/hb-ot-shape-complex-hangul.cc +++ b/src/hb-ot-shape-complex-hangul.cc @@ -414,7 +414,6 @@ setup_masks_hangul (const hb_ot_shape_plan_t *plan, const hb_ot_complex_shaper_t _hb_ot_complex_shaper_hangul = { - "hangul", collect_features_hangul, override_features_hangul, data_create_hangul, diff --git a/src/hb-ot-shape-complex-hebrew.cc b/src/hb-ot-shape-complex-hebrew.cc index fccd76a4..ba78186a 100644 --- a/src/hb-ot-shape-complex-hebrew.cc +++ b/src/hb-ot-shape-complex-hebrew.cc @@ -169,7 +169,6 @@ disable_otl_hebrew (const hb_ot_shape_plan_t *plan) const hb_ot_complex_shaper_t _hb_ot_complex_shaper_hebrew = { - "hebrew", nullptr, /* collect_features */ nullptr, /* override_features */ nullptr, /* data_create */ diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 05a51369..1937380b 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -1843,7 +1843,6 @@ compose_indic (const hb_ot_shape_normalize_context_t *c, const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic = { - "indic", collect_features_indic, override_features_indic, data_create_indic, diff --git a/src/hb-ot-shape-complex-myanmar.cc b/src/hb-ot-shape-complex-myanmar.cc index f446fe62..5ea1dbff 100644 --- a/src/hb-ot-shape-complex-myanmar.cc +++ b/src/hb-ot-shape-complex-myanmar.cc @@ -512,7 +512,6 @@ final_reordering (const hb_ot_shape_plan_t *plan, * generic shaper, except that it zeros mark advances GDEF_LATE. */ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_old = { - "default", nullptr, /* collect_features */ nullptr, /* override_features */ nullptr, /* data_create */ @@ -531,7 +530,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_old = const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar = { - "myanmar", collect_features_myanmar, override_features_myanmar, nullptr, /* data_create */ diff --git a/src/hb-ot-shape-complex-private.hh b/src/hb-ot-shape-complex-private.hh index 4951cb5f..fb2f6115 100644 --- a/src/hb-ot-shape-complex-private.hh +++ b/src/hb-ot-shape-complex-private.hh @@ -65,8 +65,6 @@ enum hb_ot_shape_zero_width_marks_type_t { struct hb_ot_complex_shaper_t { - char name[8]; - /* collect_features() * Called during shape_plan(). * Shapers should use plan->map to add their features and callbacks. diff --git a/src/hb-ot-shape-complex-thai.cc b/src/hb-ot-shape-complex-thai.cc index 58a0a41e..6ba925c6 100644 --- a/src/hb-ot-shape-complex-thai.cc +++ b/src/hb-ot-shape-complex-thai.cc @@ -366,7 +366,6 @@ preprocess_text_thai (const hb_ot_shape_plan_t *plan, const hb_ot_complex_shaper_t _hb_ot_complex_shaper_thai = { - "thai", nullptr, /* collect_features */ nullptr, /* override_features */ nullptr, /* data_create */ diff --git a/src/hb-ot-shape-complex-tibetan.cc b/src/hb-ot-shape-complex-tibetan.cc index e87f1a4e..eaac0bf6 100644 --- a/src/hb-ot-shape-complex-tibetan.cc +++ b/src/hb-ot-shape-complex-tibetan.cc @@ -46,7 +46,6 @@ collect_features_tibetan (hb_ot_shape_planner_t *plan) const hb_ot_complex_shaper_t _hb_ot_complex_shaper_tibetan = { - "default", collect_features_tibetan, nullptr, /* override_features */ nullptr, /* data_create */ diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc index a2cacac5..62acd697 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc @@ -595,7 +595,6 @@ compose_use (const hb_ot_shape_normalize_context_t *c, const hb_ot_complex_shaper_t _hb_ot_complex_shaper_use = { - "use", collect_features_use, nullptr, /* override_features */ data_create_use, _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
