Port objects to use header.writable instead of immutable
Saves 4 or 8 bytes per object on 64bit archs.
diff --git a/src/hb-blob.cc b/src/hb-blob.cc
index 51f22ce..4b036e8 100644
--- a/src/hb-blob.cc
+++ b/src/hb-blob.cc
@@ -57,8 +57,6 @@
{
HB_OBJECT_HEADER_STATIC,
- true, /* immutable */
-
nullptr, /* data */
0, /* length */
HB_MEMORY_MODE_READONLY, /* mode */
@@ -299,12 +297,10 @@
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_bool_t
hb_blob_is_immutable (hb_blob_t *blob)
{
- return blob->immutable;
+ return hb_object_is_immutable (blob);
}
@@ -454,7 +450,7 @@
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)
diff --git a/src/hb-blob.hh b/src/hb-blob.hh
index 0181e94..1f7499f 100644
--- a/src/hb-blob.hh
+++ b/src/hb-blob.hh
@@ -70,8 +70,6 @@
public:
hb_object_header_t header;
- bool immutable;
-
const char *data;
unsigned int length;
hb_memory_mode_t mode;
diff --git a/src/hb-face.cc b/src/hb-face.cc
index 7ca4b1b..50ab10e 100644
--- a/src/hb-face.cc
+++ b/src/hb-face.cc
@@ -82,8 +82,6 @@
{
HB_OBJECT_HEADER_STATIC,
- true, /* immutable */
-
nullptr, /* reference_table_func */
nullptr, /* user_data */
nullptr, /* destroy */
@@ -336,12 +334,10 @@
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_bool_t
hb_face_is_immutable (const hb_face_t *face)
{
- return face->immutable;
+ return hb_object_is_immutable (face);
}
@@ -408,7 +404,7 @@
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 @@
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 @@
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;
diff --git a/src/hb-face.hh b/src/hb-face.hh
index 89673ff..520bdfd 100644
--- a/src/hb-face.hh
+++ b/src/hb-face.hh
@@ -43,8 +43,6 @@
{
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;
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 86b03f4..567cded 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -471,8 +471,6 @@
{
HB_OBJECT_HEADER_STATIC,
- true, /* immutable */
-
{
#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
@@ -495,8 +493,6 @@
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 @@
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_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 @@
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 @@
{
HB_OBJECT_HEADER_STATIC,
- true, /* immutable */
-
nullptr, /* parent */
const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
@@ -1525,15 +1517,13 @@
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_bool_t
hb_font_is_immutable (hb_font_t *font)
{
- return font->immutable;
+ return hb_object_is_immutable (font);
}
/**
@@ -1565,7 +1555,7 @@
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 @@
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 @@
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_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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
diff --git a/src/hb-font.hh b/src/hb-font.hh
index 3dce233..fb29bcc 100644
--- a/src/hb-font.hh
+++ b/src/hb-font.hh
@@ -63,8 +63,6 @@
{
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 @@
{
hb_object_header_t header;
- hb_bool_t immutable;
-
hb_font_t *parent;
hb_face_t *face;
diff --git a/src/hb-ft.cc b/src/hb-ft.cc
index 5e05110..8b80b96 100644
--- a/src/hb-ft.cc
+++ b/src/hb-ft.cc
@@ -135,7 +135,7 @@
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)
diff --git a/src/hb-object.hh b/src/hb-object.hh
index 309aa2b..74340c5 100644
--- a/src/hb-object.hh
+++ b/src/hb-object.hh
@@ -197,7 +197,12 @@
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 @@
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)
diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc
index 8cf7898..5accf36 100644
--- a/src/hb-unicode.cc
+++ b/src/hb-unicode.cc
@@ -187,7 +187,6 @@
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 @@
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_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 @@
void *user_data, \
hb_destroy_func_t destroy) \
{ \
- if (ufuncs->immutable) \
+ if (hb_object_is_immutable (ufuncs)) \
return; \
\
if (ufuncs->destroy.name) \
diff --git a/src/hb-unicode.hh b/src/hb-unicode.hh
index 0b66ce8..d3fd5ea 100644
--- a/src/hb-unicode.hh
+++ b/src/hb-unicode.hh
@@ -66,8 +66,6 @@
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