提交 5570c87f 编写于 作者: B Behdad Esfahbod

Port objects to use header.writable instead of immutable

Saves 4 or 8 bytes per object on 64bit archs.
上级 ee351a38
......@@ -57,8 +57,6 @@ DEFINE_NULL_INSTANCE (hb_blob_t) =
{
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* data */
0, /* length */
HB_MEMORY_MODE_READONLY, /* mode */
......@@ -299,12 +297,10 @@ hb_blob_get_user_data (hb_blob_t *blob,
void
hb_blob_make_immutable (hb_blob_t *blob)
{
if (hb_object_is_inert (blob))
return;
if (blob->immutable)
if (hb_object_is_immutable (blob))
return;
blob->immutable = true;
hb_object_make_immutable (blob);
}
/**
......@@ -320,7 +316,7 @@ hb_blob_make_immutable (hb_blob_t *blob)
hb_bool_t
hb_blob_is_immutable (hb_blob_t *blob)
{
return blob->immutable;
return hb_object_is_immutable (blob);
}
......@@ -454,7 +450,7 @@ hb_blob_t::try_make_writable_inplace (void)
bool
hb_blob_t::try_make_writable (void)
{
if (this->immutable)
if (hb_object_is_immutable (this))
return false;
if (this->mode == HB_MEMORY_MODE_WRITABLE)
......
......@@ -70,8 +70,6 @@ struct hb_blob_t
public:
hb_object_header_t header;
bool immutable;
const char *data;
unsigned int length;
hb_memory_mode_t mode;
......
......@@ -82,8 +82,6 @@ DEFINE_NULL_INSTANCE (hb_face_t) =
{
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* reference_table_func */
nullptr, /* user_data */
nullptr, /* destroy */
......@@ -336,12 +334,10 @@ hb_face_get_user_data (const hb_face_t *face,
void
hb_face_make_immutable (hb_face_t *face)
{
if (unlikely (hb_object_is_inert (face)))
return;
if (face->immutable)
if (hb_object_is_immutable (face))
return;
face->immutable = true;
hb_object_make_immutable (face);
}
/**
......@@ -357,7 +353,7 @@ hb_face_make_immutable (hb_face_t *face)
hb_bool_t
hb_face_is_immutable (const hb_face_t *face)
{
return face->immutable;
return hb_object_is_immutable (face);
}
......@@ -408,7 +404,7 @@ void
hb_face_set_index (hb_face_t *face,
unsigned int index)
{
if (face->immutable)
if (hb_object_is_immutable (face))
return;
face->index = index;
......@@ -443,7 +439,7 @@ void
hb_face_set_upem (hb_face_t *face,
unsigned int upem)
{
if (face->immutable)
if (hb_object_is_immutable (face))
return;
face->upem = upem;
......@@ -478,7 +474,7 @@ void
hb_face_set_glyph_count (hb_face_t *face,
unsigned int glyph_count)
{
if (face->immutable)
if (hb_object_is_immutable (face))
return;
face->num_glyphs = glyph_count;
......
......@@ -43,8 +43,6 @@ struct hb_face_t
{
hb_object_header_t header;
hb_bool_t immutable;
hb_reference_table_func_t reference_table_func;
void *user_data;
hb_destroy_func_t destroy;
......
......@@ -471,8 +471,6 @@ DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
{
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
{
#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
......@@ -495,8 +493,6 @@ DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
static const hb_font_funcs_t _hb_font_funcs_default = {
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
{
#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
......@@ -645,12 +641,10 @@ hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
void
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
{
if (unlikely (hb_object_is_inert (ffuncs)))
return;
if (ffuncs->immutable)
if (hb_object_is_immutable (ffuncs))
return;
ffuncs->immutable = true;
hb_object_make_immutable (ffuncs);
}
/**
......@@ -666,7 +660,7 @@ hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
hb_bool_t
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
{
return ffuncs->immutable;
return hb_object_is_immutable (ffuncs);
}
......@@ -678,7 +672,7 @@ hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
void *user_data, \
hb_destroy_func_t destroy) \
{ \
if (ffuncs->immutable) { \
if (hb_object_is_immutable (ffuncs)) { \
if (destroy) \
destroy (user_data); \
return; \
......@@ -1299,8 +1293,6 @@ DEFINE_NULL_INSTANCE (hb_font_t) =
{
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* parent */
const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
......@@ -1525,15 +1517,13 @@ hb_font_get_user_data (hb_font_t *font,
void
hb_font_make_immutable (hb_font_t *font)
{
if (unlikely (hb_object_is_inert (font)))
return;
if (font->immutable)
if (hb_object_is_immutable (font))
return;
if (font->parent)
hb_font_make_immutable (font->parent);
font->immutable = true;
hb_object_make_immutable (font);
}
/**
......@@ -1549,7 +1539,7 @@ hb_font_make_immutable (hb_font_t *font)
hb_bool_t
hb_font_is_immutable (hb_font_t *font)
{
return font->immutable;
return hb_object_is_immutable (font);
}
/**
......@@ -1565,7 +1555,7 @@ void
hb_font_set_parent (hb_font_t *font,
hb_font_t *parent)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
if (!parent)
......@@ -1607,7 +1597,7 @@ void
hb_font_set_face (hb_font_t *font,
hb_face_t *face)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
if (unlikely (!face))
......@@ -1654,7 +1644,8 @@ hb_font_set_funcs (hb_font_t *font,
void *font_data,
hb_destroy_func_t destroy)
{
if (font->immutable) {
if (hb_object_is_immutable (font))
{
if (destroy)
destroy (font_data);
return;
......@@ -1689,7 +1680,8 @@ hb_font_set_funcs_data (hb_font_t *font,
hb_destroy_func_t destroy)
{
/* Destroy user_data? */
if (font->immutable) {
if (hb_object_is_immutable (font))
{
if (destroy)
destroy (font_data);
return;
......@@ -1718,7 +1710,7 @@ hb_font_set_scale (hb_font_t *font,
int x_scale,
int y_scale)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
font->x_scale = x_scale;
......@@ -1759,7 +1751,7 @@ hb_font_set_ppem (hb_font_t *font,
unsigned int x_ppem,
unsigned int y_ppem)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
font->x_ppem = x_ppem;
......@@ -1799,7 +1791,7 @@ hb_font_get_ppem (hb_font_t *font,
void
hb_font_set_ptem (hb_font_t *font, float ptem)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
font->ptem = ptem;
......@@ -1846,7 +1838,7 @@ hb_font_set_variations (hb_font_t *font,
const hb_variation_t *variations,
unsigned int variations_length)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
if (!variations_length)
......@@ -1877,7 +1869,7 @@ hb_font_set_var_coords_design (hb_font_t *font,
const float *coords,
unsigned int coords_length)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;
......@@ -1898,7 +1890,7 @@ hb_font_set_var_coords_normalized (hb_font_t *font,
const int *coords, /* 2.14 normalized */
unsigned int coords_length)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;
......
......@@ -63,8 +63,6 @@ struct hb_font_funcs_t
{
hb_object_header_t header;
hb_bool_t immutable;
struct {
#define HB_FONT_FUNC_IMPLEMENT(name) void *name;
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
......@@ -102,8 +100,6 @@ struct hb_font_t
{
hb_object_header_t header;
hb_bool_t immutable;
hb_font_t *parent;
hb_face_t *face;
......
......@@ -135,7 +135,7 @@ _hb_ft_font_destroy (void *data)
void
hb_ft_font_set_load_flags (hb_font_t *font, int load_flags)
{
if (font->immutable)
if (hb_object_is_immutable (font))
return;
if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)
......
......@@ -197,7 +197,12 @@ struct hb_object_header_t
hb_atomic_int_t writable;
hb_atomic_ptr_t<hb_user_data_array_t> user_data;
};
#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, HB_ATOMIC_INT_INIT (0), HB_ATOMIC_PTR_INIT (nullptr)}
#define HB_OBJECT_HEADER_STATIC \
{ \
HB_REFERENCE_COUNT_INIT, \
HB_ATOMIC_INT_INIT (false), \
HB_ATOMIC_PTR_INIT (nullptr) \
}
/*
......@@ -248,9 +253,9 @@ static inline bool hb_object_is_immutable (const Type *obj)
return !obj->header.writable.get_relaxed ();
}
template <typename Type>
static inline bool hb_object_make_immutable (const Type *obj)
static inline void hb_object_make_immutable (const Type *obj)
{
return !obj->header.writable.set_relaxed (false);
obj->header.writable.set_relaxed (false);
}
template <typename Type>
static inline Type *hb_object_reference (Type *obj)
......
......@@ -187,7 +187,6 @@ DEFINE_NULL_INSTANCE (hb_unicode_funcs_t) =
HB_OBJECT_HEADER_STATIC,
nullptr, /* parent */
true, /* immutable */
{
#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil,
HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
......@@ -303,12 +302,10 @@ hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs,
void
hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
{
if (unlikely (hb_object_is_inert (ufuncs)))
return;
if (ufuncs->immutable)
if (hb_object_is_immutable (ufuncs))
return;
ufuncs->immutable = true;
hb_object_make_immutable (ufuncs);
}
/**
......@@ -324,7 +321,7 @@ hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
hb_bool_t
hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
{
return ufuncs->immutable;
return hb_object_is_immutable (ufuncs);
}
/**
......@@ -352,7 +349,7 @@ hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \
void *user_data, \
hb_destroy_func_t destroy) \
{ \
if (ufuncs->immutable) \
if (hb_object_is_immutable (ufuncs)) \
return; \
\
if (ufuncs->destroy.name) \
......
......@@ -66,8 +66,6 @@ struct hb_unicode_funcs_t
hb_unicode_funcs_t *parent;
bool immutable;
#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \
inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); }
HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册