Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / harfbuzz-ng / src / hb-object-private.hh
index 8a9ae34..7bd0f16 100644 (file)
@@ -68,8 +68,6 @@ struct hb_reference_count_t
 #define HB_USER_DATA_ARRAY_INIT {HB_MUTEX_INIT, HB_LOCKABLE_SET_INIT}
 struct hb_user_data_array_t
 {
-  /* TODO Add tracing. */
-
   struct hb_user_data_item_t {
     hb_user_data_key_t *key;
     void *data;
@@ -106,69 +104,6 @@ struct hb_object_header_t
 
 #define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_USER_DATA_ARRAY_INIT}
 
-  static inline void *create (unsigned int size) {
-    hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size);
-
-    if (likely (obj))
-      obj->init ();
-
-    return obj;
-  }
-
-  inline void init (void) {
-    ref_count.init (1);
-    user_data.init ();
-  }
-
-  inline bool is_inert (void) const {
-    return unlikely (ref_count.is_invalid ());
-  }
-
-  inline void reference (void) {
-    if (unlikely (!this || this->is_inert ()))
-      return;
-    ref_count.inc ();
-  }
-
-  inline bool destroy (void) {
-    if (unlikely (!this || this->is_inert ()))
-      return false;
-    if (ref_count.dec () != 1)
-      return false;
-
-    ref_count.finish (); /* Do this before user_data */
-    user_data.finish ();
-
-    return true;
-  }
-
-  inline bool set_user_data (hb_user_data_key_t *key,
-                            void *              data,
-                            hb_destroy_func_t   destroy_func,
-                            hb_bool_t           replace) {
-    if (unlikely (!this || this->is_inert ()))
-      return false;
-
-    return user_data.set (key, data, destroy_func, replace);
-  }
-
-  inline void *get_user_data (hb_user_data_key_t *key) {
-    if (unlikely (!this || this->is_inert ()))
-      return NULL;
-
-    return user_data.get (key);
-  }
-
-  inline void trace (const char *function) const {
-    if (unlikely (!this)) return;
-    /* TODO We cannot use DEBUG_MSG_FUNC here since that one currently only
-     * prints the class name and throws away the template info. */
-    DEBUG_MSG (OBJECT, (void *) this,
-              "%s refcount=%d",
-              function,
-              this ? ref_count.ref_count : 0);
-  }
-
   private:
   ASSERT_POD ();
 };
@@ -179,32 +114,56 @@ struct hb_object_header_t
 template <typename Type>
 static inline void hb_object_trace (const Type *obj, const char *function)
 {
-  obj->header.trace (function);
+  DEBUG_MSG (OBJECT, (void *) obj,
+            "%s refcount=%d",
+            function,
+            obj ? obj->header.ref_count.ref_count : 0);
 }
+
 template <typename Type>
 static inline Type *hb_object_create (void)
 {
-  Type *obj = (Type *) hb_object_header_t::create (sizeof (Type));
+  Type *obj = (Type *) calloc (1, sizeof (Type));
+
+  if (unlikely (!obj))
+    return obj;
+
+  hb_object_init (obj);
   hb_object_trace (obj, HB_FUNC);
   return obj;
 }
 template <typename Type>
+static inline void hb_object_init (Type *obj)
+{
+  obj->header.ref_count.init (1);
+  obj->header.user_data.init ();
+}
+template <typename Type>
 static inline bool hb_object_is_inert (const Type *obj)
 {
-  return unlikely (obj->header.is_inert ());
+  return unlikely (obj->header.ref_count.is_invalid ());
 }
 template <typename Type>
 static inline Type *hb_object_reference (Type *obj)
 {
   hb_object_trace (obj, HB_FUNC);
-  obj->header.reference ();
+  if (unlikely (!obj || hb_object_is_inert (obj)))
+    return obj;
+  obj->header.ref_count.inc ();
   return obj;
 }
 template <typename Type>
 static inline bool hb_object_destroy (Type *obj)
 {
   hb_object_trace (obj, HB_FUNC);
-  return obj->header.destroy ();
+  if (unlikely (!obj || hb_object_is_inert (obj)))
+    return false;
+  if (obj->header.ref_count.dec () != 1)
+    return false;
+
+  obj->header.ref_count.finish (); /* Do this before user_data */
+  obj->header.user_data.finish ();
+  return true;
 }
 template <typename Type>
 static inline bool hb_object_set_user_data (Type               *obj,
@@ -213,14 +172,18 @@ static inline bool hb_object_set_user_data (Type               *obj,
                                            hb_destroy_func_t   destroy,
                                            hb_bool_t           replace)
 {
-  return obj->header.set_user_data (key, data, destroy, replace);
+  if (unlikely (!obj || hb_object_is_inert (obj)))
+    return false;
+  return obj->header.user_data.set (key, data, destroy, replace);
 }
 
 template <typename Type>
 static inline void *hb_object_get_user_data (Type               *obj,
                                             hb_user_data_key_t *key)
 {
-  return obj->header.get_user_data (key);
+  if (unlikely (!obj || hb_object_is_inert (obj)))
+    return NULL;
+  return obj->header.user_data.get (key);
 }