summaryrefslogtreecommitdiff
path: root/src/hb-icu.cc
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2017-10-27 15:26:45 -0600
committerBehdad Esfahbod <behdad@behdad.org>2017-10-27 15:26:45 -0600
commit8864864b624590d95ae5dca61956695cbff1269a (patch)
treec653a89c91f22ff44a56ef343755bf09a9f39715 /src/hb-icu.cc
parentaf3f72f9eb7d7b80ea827976a3303390b5deae8d (diff)
[glib/icu/ucdn] Make the funcs object allocated on demand
Diffstat (limited to 'src/hb-icu.cc')
-rw-r--r--src/hb-icu.cc51
1 files changed, 37 insertions, 14 deletions
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;
}