Port objects to use header.writable instead of immutable

Saves 4 or 8 bytes per object on 64bit archs.
This commit is contained in:
Behdad Esfahbod 2018-11-03 14:51:38 -04:00
parent ee351a38ec
commit 5570c87f21
10 changed files with 42 additions and 66 deletions

View File

@ -57,8 +57,6 @@ DEFINE_NULL_INSTANCE (hb_blob_t) =
{ {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* data */ nullptr, /* data */
0, /* length */ 0, /* length */
HB_MEMORY_MODE_READONLY, /* mode */ HB_MEMORY_MODE_READONLY, /* mode */
@ -299,12 +297,10 @@ hb_blob_get_user_data (hb_blob_t *blob,
void void
hb_blob_make_immutable (hb_blob_t *blob) hb_blob_make_immutable (hb_blob_t *blob)
{ {
if (hb_object_is_inert (blob)) if (hb_object_is_immutable (blob))
return;
if (blob->immutable)
return; 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_bool_t
hb_blob_is_immutable (hb_blob_t *blob) 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 bool
hb_blob_t::try_make_writable (void) hb_blob_t::try_make_writable (void)
{ {
if (this->immutable) if (hb_object_is_immutable (this))
return false; return false;
if (this->mode == HB_MEMORY_MODE_WRITABLE) if (this->mode == HB_MEMORY_MODE_WRITABLE)

View File

@ -70,8 +70,6 @@ struct hb_blob_t
public: public:
hb_object_header_t header; hb_object_header_t header;
bool immutable;
const char *data; const char *data;
unsigned int length; unsigned int length;
hb_memory_mode_t mode; hb_memory_mode_t mode;

View File

@ -82,8 +82,6 @@ DEFINE_NULL_INSTANCE (hb_face_t) =
{ {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* reference_table_func */ nullptr, /* reference_table_func */
nullptr, /* user_data */ nullptr, /* user_data */
nullptr, /* destroy */ nullptr, /* destroy */
@ -336,12 +334,10 @@ hb_face_get_user_data (const hb_face_t *face,
void void
hb_face_make_immutable (hb_face_t *face) hb_face_make_immutable (hb_face_t *face)
{ {
if (unlikely (hb_object_is_inert (face))) if (hb_object_is_immutable (face))
return;
if (face->immutable)
return; 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_bool_t
hb_face_is_immutable (const hb_face_t *face) 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, hb_face_set_index (hb_face_t *face,
unsigned int index) unsigned int index)
{ {
if (face->immutable) if (hb_object_is_immutable (face))
return; return;
face->index = index; face->index = index;
@ -443,7 +439,7 @@ void
hb_face_set_upem (hb_face_t *face, hb_face_set_upem (hb_face_t *face,
unsigned int upem) unsigned int upem)
{ {
if (face->immutable) if (hb_object_is_immutable (face))
return; return;
face->upem = upem; face->upem = upem;
@ -478,7 +474,7 @@ void
hb_face_set_glyph_count (hb_face_t *face, hb_face_set_glyph_count (hb_face_t *face,
unsigned int glyph_count) unsigned int glyph_count)
{ {
if (face->immutable) if (hb_object_is_immutable (face))
return; return;
face->num_glyphs = glyph_count; face->num_glyphs = glyph_count;

View File

@ -43,8 +43,6 @@ struct hb_face_t
{ {
hb_object_header_t header; hb_object_header_t header;
hb_bool_t immutable;
hb_reference_table_func_t reference_table_func; hb_reference_table_func_t reference_table_func;
void *user_data; void *user_data;
hb_destroy_func_t destroy; hb_destroy_func_t destroy;

View File

@ -471,8 +471,6 @@ DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
{ {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
true, /* immutable */
{ {
#define HB_FONT_FUNC_IMPLEMENT(name) nullptr, #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 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 = { static const hb_font_funcs_t _hb_font_funcs_default = {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
true, /* immutable */
{ {
#define HB_FONT_FUNC_IMPLEMENT(name) nullptr, #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
@ -645,12 +641,10 @@ hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
void void
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
{ {
if (unlikely (hb_object_is_inert (ffuncs))) if (hb_object_is_immutable (ffuncs))
return;
if (ffuncs->immutable)
return; 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_bool_t
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) 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, \ void *user_data, \
hb_destroy_func_t destroy) \ hb_destroy_func_t destroy) \
{ \ { \
if (ffuncs->immutable) { \ if (hb_object_is_immutable (ffuncs)) { \
if (destroy) \ if (destroy) \
destroy (user_data); \ destroy (user_data); \
return; \ return; \
@ -1299,8 +1293,6 @@ DEFINE_NULL_INSTANCE (hb_font_t) =
{ {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* parent */ nullptr, /* parent */
const_cast<hb_face_t *> (&_hb_Null_hb_face_t), const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
@ -1525,15 +1517,13 @@ hb_font_get_user_data (hb_font_t *font,
void void
hb_font_make_immutable (hb_font_t *font) hb_font_make_immutable (hb_font_t *font)
{ {
if (unlikely (hb_object_is_inert (font))) if (hb_object_is_immutable (font))
return;
if (font->immutable)
return; return;
if (font->parent) if (font->parent)
hb_font_make_immutable (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_bool_t
hb_font_is_immutable (hb_font_t *font) 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_set_parent (hb_font_t *font,
hb_font_t *parent) hb_font_t *parent)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
if (!parent) if (!parent)
@ -1607,7 +1597,7 @@ void
hb_font_set_face (hb_font_t *font, hb_font_set_face (hb_font_t *font,
hb_face_t *face) hb_face_t *face)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
if (unlikely (!face)) if (unlikely (!face))
@ -1654,7 +1644,8 @@ hb_font_set_funcs (hb_font_t *font,
void *font_data, void *font_data,
hb_destroy_func_t destroy) hb_destroy_func_t destroy)
{ {
if (font->immutable) { if (hb_object_is_immutable (font))
{
if (destroy) if (destroy)
destroy (font_data); destroy (font_data);
return; return;
@ -1689,7 +1680,8 @@ hb_font_set_funcs_data (hb_font_t *font,
hb_destroy_func_t destroy) hb_destroy_func_t destroy)
{ {
/* Destroy user_data? */ /* Destroy user_data? */
if (font->immutable) { if (hb_object_is_immutable (font))
{
if (destroy) if (destroy)
destroy (font_data); destroy (font_data);
return; return;
@ -1718,7 +1710,7 @@ hb_font_set_scale (hb_font_t *font,
int x_scale, int x_scale,
int y_scale) int y_scale)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
font->x_scale = x_scale; font->x_scale = x_scale;
@ -1759,7 +1751,7 @@ hb_font_set_ppem (hb_font_t *font,
unsigned int x_ppem, unsigned int x_ppem,
unsigned int y_ppem) unsigned int y_ppem)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
font->x_ppem = x_ppem; font->x_ppem = x_ppem;
@ -1799,7 +1791,7 @@ hb_font_get_ppem (hb_font_t *font,
void void
hb_font_set_ptem (hb_font_t *font, float ptem) hb_font_set_ptem (hb_font_t *font, float ptem)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
font->ptem = ptem; font->ptem = ptem;
@ -1846,7 +1838,7 @@ hb_font_set_variations (hb_font_t *font,
const hb_variation_t *variations, const hb_variation_t *variations,
unsigned int variations_length) unsigned int variations_length)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
if (!variations_length) if (!variations_length)
@ -1877,7 +1869,7 @@ hb_font_set_var_coords_design (hb_font_t *font,
const float *coords, const float *coords,
unsigned int coords_length) unsigned int coords_length)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr; 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 */ const int *coords, /* 2.14 normalized */
unsigned int coords_length) unsigned int coords_length)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr; int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;

View File

@ -63,8 +63,6 @@ struct hb_font_funcs_t
{ {
hb_object_header_t header; hb_object_header_t header;
hb_bool_t immutable;
struct { struct {
#define HB_FONT_FUNC_IMPLEMENT(name) void *name; #define HB_FONT_FUNC_IMPLEMENT(name) void *name;
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
@ -102,8 +100,6 @@ struct hb_font_t
{ {
hb_object_header_t header; hb_object_header_t header;
hb_bool_t immutable;
hb_font_t *parent; hb_font_t *parent;
hb_face_t *face; hb_face_t *face;

View File

@ -135,7 +135,7 @@ _hb_ft_font_destroy (void *data)
void void
hb_ft_font_set_load_flags (hb_font_t *font, int load_flags) hb_ft_font_set_load_flags (hb_font_t *font, int load_flags)
{ {
if (font->immutable) if (hb_object_is_immutable (font))
return; return;
if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy) if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)

View File

@ -197,7 +197,12 @@ struct hb_object_header_t
hb_atomic_int_t writable; hb_atomic_int_t writable;
hb_atomic_ptr_t<hb_user_data_array_t> user_data; 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 (); return !obj->header.writable.get_relaxed ();
} }
template <typename Type> 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> template <typename Type>
static inline Type *hb_object_reference (Type *obj) static inline Type *hb_object_reference (Type *obj)

View File

@ -187,7 +187,6 @@ DEFINE_NULL_INSTANCE (hb_unicode_funcs_t) =
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
nullptr, /* parent */ nullptr, /* parent */
true, /* immutable */
{ {
#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil, #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil,
HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
@ -303,12 +302,10 @@ hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs,
void void
hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs) hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
{ {
if (unlikely (hb_object_is_inert (ufuncs))) if (hb_object_is_immutable (ufuncs))
return;
if (ufuncs->immutable)
return; 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_bool_t
hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs) 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, \ void *user_data, \
hb_destroy_func_t destroy) \ hb_destroy_func_t destroy) \
{ \ { \
if (ufuncs->immutable) \ if (hb_object_is_immutable (ufuncs)) \
return; \ return; \
\ \
if (ufuncs->destroy.name) \ if (ufuncs->destroy.name) \

View File

@ -66,8 +66,6 @@ struct hb_unicode_funcs_t
hb_unicode_funcs_t *parent; hb_unicode_funcs_t *parent;
bool immutable;
#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \
inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); } inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); }
HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE