提交 1f810daf 编写于 作者: B Behdad Esfahbod

Port math table to hb_lazy_table_loader_t

上级 ebbcc111
...@@ -1064,6 +1064,7 @@ struct SortedArrayOf : ArrayOf<Type, LenType> ...@@ -1064,6 +1064,7 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
/* Lazy struct and blob loaders. */ /* Lazy struct and blob loaders. */
/* Logic is shared between hb_lazy_loader_t and hb_lazy_table_loader_t */
template <typename T> template <typename T>
struct hb_lazy_loader_t struct hb_lazy_loader_t
{ {
...@@ -1082,7 +1083,7 @@ struct hb_lazy_loader_t ...@@ -1082,7 +1083,7 @@ struct hb_lazy_loader_t
} }
} }
inline const T* operator-> (void) const inline const T* get (void) const
{ {
retry: retry:
T *p = (T *) hb_atomic_ptr_get (&instance); T *p = (T *) hb_atomic_ptr_get (&instance);
...@@ -1103,11 +1104,17 @@ struct hb_lazy_loader_t ...@@ -1103,11 +1104,17 @@ struct hb_lazy_loader_t
return p; return p;
} }
inline const T* operator-> (void) const
{
return get ();
}
private: private:
hb_face_t *face; hb_face_t *face;
T *instance; T *instance;
}; };
/* Logic is shared between hb_lazy_loader_t and hb_lazy_table_loader_t */
template <typename T> template <typename T>
struct hb_lazy_table_loader_t struct hb_lazy_table_loader_t
{ {
...@@ -1123,14 +1130,14 @@ struct hb_lazy_table_loader_t ...@@ -1123,14 +1130,14 @@ struct hb_lazy_table_loader_t
hb_blob_destroy (blob); hb_blob_destroy (blob);
} }
inline const T* operator-> (void) const inline const T* get (void) const
{ {
retry: retry:
T *p = (T *) hb_atomic_ptr_get (&instance); const T *p = (T *) hb_atomic_ptr_get (&instance);
if (unlikely (!p)) if (unlikely (!p))
{ {
hb_blob_t *blob_ = OT::Sanitizer<T>::sanitize (face->reference_table (T::tableTag)); hb_blob_t *blob_ = OT::Sanitizer<T>::sanitize (face->reference_table (T::tableTag));
p = OT::Sanitizer<T>::lock_instance (blob); p = OT::Sanitizer<T>::lock_instance (blob_);
if (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), NULL, p)) if (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), NULL, p))
{ {
hb_blob_destroy (blob_); hb_blob_destroy (blob_);
...@@ -1141,10 +1148,15 @@ struct hb_lazy_table_loader_t ...@@ -1141,10 +1148,15 @@ struct hb_lazy_table_loader_t
return p; return p;
} }
inline const T* operator-> (void) const
{
return get();
}
private: private:
hb_face_t *face; hb_face_t *face;
T *instance; T *instance;
hb_blob_t *blob; mutable hb_blob_t *blob;
}; };
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "hb-font-private.hh" #include "hb-font-private.hh"
#include "hb-buffer-private.hh" #include "hb-buffer-private.hh"
#include "hb-set-private.hh" #include "hb-set-private.hh"
#include "hb-open-type-private.hh"
/* Private API corresponding to hb-ot-layout.h: */ /* Private API corresponding to hb-ot-layout.h: */
...@@ -153,12 +154,11 @@ struct hb_ot_layout_t ...@@ -153,12 +154,11 @@ struct hb_ot_layout_t
hb_blob_t *gdef_blob; hb_blob_t *gdef_blob;
hb_blob_t *gsub_blob; hb_blob_t *gsub_blob;
hb_blob_t *gpos_blob; hb_blob_t *gpos_blob;
hb_blob_t *math_blob;
const struct OT::GDEF *gdef; const struct OT::GDEF *gdef;
const struct OT::GSUB *gsub; const struct OT::GSUB *gsub;
const struct OT::GPOS *gpos; const struct OT::GPOS *gpos;
const struct OT::MATH *math; OT::hb_lazy_table_loader_t<struct OT::MATH> math;
unsigned int gsub_lookup_count; unsigned int gsub_lookup_count;
unsigned int gpos_lookup_count; unsigned int gpos_lookup_count;
......
...@@ -60,9 +60,7 @@ _hb_ot_layout_create (hb_face_t *face) ...@@ -60,9 +60,7 @@ _hb_ot_layout_create (hb_face_t *face)
layout->gpos_blob = OT::Sanitizer<OT::GPOS>::sanitize (face->reference_table (HB_OT_TAG_GPOS)); layout->gpos_blob = OT::Sanitizer<OT::GPOS>::sanitize (face->reference_table (HB_OT_TAG_GPOS));
layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob); layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob);
/* The MATH table is rarely used, so only try and load it in _get_math. */ layout->math.init (face);
layout->math_blob = NULL;
layout->math = NULL;
{ {
/* /*
...@@ -181,7 +179,8 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) ...@@ -181,7 +179,8 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout)
hb_blob_destroy (layout->gdef_blob); hb_blob_destroy (layout->gdef_blob);
hb_blob_destroy (layout->gsub_blob); hb_blob_destroy (layout->gsub_blob);
hb_blob_destroy (layout->gpos_blob); hb_blob_destroy (layout->gpos_blob);
hb_blob_destroy (layout->math_blob);
layout->math.fini ();
free (layout); free (layout);
} }
......
...@@ -37,22 +37,7 @@ _get_math (hb_face_t *face) ...@@ -37,22 +37,7 @@ _get_math (hb_face_t *face)
hb_ot_layout_t * layout = hb_ot_layout_from_face (face); hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
retry: return *(layout->math.get ());
const OT::MATH *math = (const OT::MATH *) hb_atomic_ptr_get (&layout->math);
if (unlikely (!math))
{
hb_blob_t *blob = OT::Sanitizer<OT::MATH>::sanitize (face->reference_table (HB_OT_TAG_MATH));
math = OT::Sanitizer<OT::MATH>::lock_instance (blob);
if (!hb_atomic_ptr_cmpexch (&layout->math, NULL, math))
{
hb_blob_destroy (blob);
goto retry;
}
layout->math_blob = blob;
}
return *math;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册