[object] Remove unnecessary use of macros

This commit is contained in:
Behdad Esfahbod 2011-04-27 16:38:03 -04:00
parent 8be1420f8f
commit 47e71d9661
6 changed files with 31 additions and 42 deletions

2
TODO
View File

@ -9,8 +9,6 @@ General fixes:
- Remove fixed-size feature/lookup arrays in hb-ot-map
- Use templates instead of macros for objects?
API issues to fix before 1.0:
============================

View File

@ -87,7 +87,7 @@ hb_blob_create (const char *data,
{
hb_blob_t *blob;
if (!length || !HB_OBJECT_DO_CREATE (hb_blob_t, blob)) {
if (!length || !(blob = hb_object_create<hb_blob_t> ())) {
if (destroy)
destroy (user_data);
return &_hb_blob_nil;
@ -122,7 +122,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent,
hb_blob_t *blob;
const char *pdata;
if (!length || offset >= parent->length || !HB_OBJECT_DO_CREATE (hb_blob_t, blob))
if (!length || offset >= parent->length || !(blob = hb_object_create<hb_blob_t> ()))
return &_hb_blob_nil;
pdata = hb_blob_lock (parent);
@ -149,13 +149,13 @@ hb_blob_create_empty (void)
hb_blob_t *
hb_blob_reference (hb_blob_t *blob)
{
HB_OBJECT_DO_REFERENCE (blob);
return hb_object_reference (blob);
}
void
hb_blob_destroy (hb_blob_t *blob)
{
HB_OBJECT_DO_DESTROY (blob);
if (!hb_object_destroy (blob)) return;
_hb_blob_destroy_user_data (blob);
@ -171,7 +171,7 @@ hb_blob_get_length (hb_blob_t *blob)
const char *
hb_blob_lock (hb_blob_t *blob)
{
if (HB_OBJECT_IS_INERT (blob))
if (hb_object_is_inert (blob))
return NULL;
hb_mutex_lock (blob->lock);
@ -190,7 +190,7 @@ hb_blob_lock (hb_blob_t *blob)
void
hb_blob_unlock (hb_blob_t *blob)
{
if (HB_OBJECT_IS_INERT (blob))
if (hb_object_is_inert (blob))
return;
hb_mutex_lock (blob->lock);
@ -210,7 +210,7 @@ hb_blob_is_writable (hb_blob_t *blob)
{
hb_memory_mode_t mode;
if (HB_OBJECT_IS_INERT (blob))
if (hb_object_is_inert (blob))
return FALSE;
hb_mutex_lock (blob->lock);
@ -292,7 +292,7 @@ hb_blob_try_writable_inplace (hb_blob_t *blob)
{
hb_memory_mode_t mode;
if (HB_OBJECT_IS_INERT (blob))
if (hb_object_is_inert (blob))
return FALSE;
hb_mutex_lock (blob->lock);
@ -312,7 +312,7 @@ hb_blob_try_writable (hb_blob_t *blob)
{
hb_memory_mode_t mode;
if (HB_OBJECT_IS_INERT (blob))
if (hb_object_is_inert (blob))
return FALSE;
hb_mutex_lock (blob->lock);

View File

@ -137,7 +137,7 @@ hb_buffer_create (unsigned int pre_alloc_size)
{
hb_buffer_t *buffer;
if (!HB_OBJECT_DO_CREATE (hb_buffer_t, buffer))
if (!(buffer = hb_object_create<hb_buffer_t> ()))
return &_hb_buffer_nil;
if (pre_alloc_size)
@ -151,13 +151,13 @@ hb_buffer_create (unsigned int pre_alloc_size)
hb_buffer_t *
hb_buffer_reference (hb_buffer_t *buffer)
{
HB_OBJECT_DO_REFERENCE (buffer);
return hb_object_reference (buffer);
}
void
hb_buffer_destroy (hb_buffer_t *buffer)
{
HB_OBJECT_DO_DESTROY (buffer);
if (!hb_object_destroy (buffer)) return;
hb_unicode_funcs_destroy (buffer->unicode);

View File

@ -102,7 +102,7 @@ hb_font_funcs_create (void)
{
hb_font_funcs_t *ffuncs;
if (!HB_OBJECT_DO_CREATE (hb_font_funcs_t, ffuncs))
if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
return &_hb_font_funcs_nil;
ffuncs->v = _hb_font_funcs_nil.v;
@ -113,13 +113,13 @@ hb_font_funcs_create (void)
hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
{
HB_OBJECT_DO_REFERENCE (ffuncs);
return hb_object_reference (ffuncs);
}
void
hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
{
HB_OBJECT_DO_DESTROY (ffuncs);
if (!hb_object_destroy (ffuncs)) return;
free (ffuncs);
}
@ -129,7 +129,7 @@ hb_font_funcs_copy (hb_font_funcs_t *other_ffuncs)
{
hb_font_funcs_t *ffuncs;
if (!HB_OBJECT_DO_CREATE (hb_font_funcs_t, ffuncs))
if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
return &_hb_font_funcs_nil;
ffuncs->v = other_ffuncs->v;
@ -140,7 +140,7 @@ hb_font_funcs_copy (hb_font_funcs_t *other_ffuncs)
void
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
{
if (HB_OBJECT_IS_INERT (ffuncs))
if (hb_object_is_inert (ffuncs))
return;
ffuncs->immutable = TRUE;
@ -308,7 +308,7 @@ hb_face_create_for_tables (hb_get_table_func_t get_table,
{
hb_face_t *face;
if (!HB_OBJECT_DO_CREATE (hb_face_t, face)) {
if (!(face = hb_object_create<hb_face_t> ())) {
if (destroy)
destroy (user_data);
return &_hb_face_nil;
@ -389,13 +389,13 @@ hb_face_create_for_data (hb_blob_t *blob,
hb_face_t *
hb_face_reference (hb_face_t *face)
{
HB_OBJECT_DO_REFERENCE (face);
return hb_object_reference (face);
}
void
hb_face_destroy (hb_face_t *face)
{
HB_OBJECT_DO_DESTROY (face);
if (!hb_object_destroy (face)) return;
_hb_ot_layout_free (face->ot_layout);
@ -454,7 +454,7 @@ hb_font_create (void)
{
hb_font_t *font;
if (!HB_OBJECT_DO_CREATE (hb_font_t, font))
if (!(font = hb_object_create<hb_font_t> ()))
return &_hb_font_nil;
font->klass = &_hb_font_funcs_nil;
@ -465,13 +465,13 @@ hb_font_create (void)
hb_font_t *
hb_font_reference (hb_font_t *font)
{
HB_OBJECT_DO_REFERENCE (font);
return hb_object_reference (font);
}
void
hb_font_destroy (hb_font_t *font)
{
HB_OBJECT_DO_DESTROY (font);
if (!hb_object_destroy (font)) return;
hb_font_funcs_destroy (font->klass);
if (font->destroy)
@ -486,7 +486,7 @@ hb_font_set_funcs (hb_font_t *font,
void *user_data,
hb_destroy_func_t destroy)
{
if (HB_OBJECT_IS_INERT (font))
if (hb_object_is_inert (font))
return;
if (font->destroy)
@ -514,7 +514,7 @@ hb_font_unset_funcs (hb_font_t *font,
*user_data = font->user_data;
*destroy = font->destroy;
if (HB_OBJECT_IS_INERT (font))
if (hb_object_is_inert (font))
return;
font->klass = NULL;
@ -527,7 +527,7 @@ hb_font_set_scale (hb_font_t *font,
int x_scale,
int y_scale)
{
if (HB_OBJECT_IS_INERT (font))
if (hb_object_is_inert (font))
return;
font->x_scale = x_scale;
@ -548,7 +548,7 @@ hb_font_set_ppem (hb_font_t *font,
unsigned int x_ppem,
unsigned int y_ppem)
{
if (HB_OBJECT_IS_INERT (font))
if (hb_object_is_inert (font))
return;
font->x_ppem = x_ppem;

View File

@ -123,18 +123,9 @@ static inline bool hb_object_destroy (Type *obj)
}
HB_BEGIN_DECLS
/* Object allocation and lifecycle manamgement macros */
#define HB_OBJECT_DO_CREATE(Type, obj) likely (obj = hb_object_create<Type> ())
#define HB_OBJECT_IS_INERT(obj) hb_object_is_inert (obj)
#define HB_OBJECT_DO_REFERENCE(obj) return hb_object_reference (obj)
#define HB_OBJECT_DO_DESTROY(obj) if (!hb_object_destroy (obj)) return
HB_END_DECLS
#endif /* HB_OBJECT_PRIVATE_HH */

View File

@ -107,7 +107,7 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
{
hb_unicode_funcs_t *ufuncs;
if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
return &_hb_unicode_funcs_nil;
if (parent != NULL)
@ -133,13 +133,13 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
hb_unicode_funcs_t *
hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
{
HB_OBJECT_DO_REFERENCE (ufuncs);
return hb_object_reference (ufuncs);
}
void
hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
{
HB_OBJECT_DO_DESTROY (ufuncs);
if (!hb_object_destroy (ufuncs)) return;
#define DESTROY(name) if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name)
DESTROY (combining_class);
@ -158,7 +158,7 @@ hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
void
hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
{
if (HB_OBJECT_IS_INERT (ufuncs))
if (hb_object_is_inert (ufuncs))
return;
ufuncs->immutable = TRUE;