likely/unlikely branch prediction
[lttv.git] / ltt / branches / poly / lttv / lttv / attribute.c
index a0d30704fd804a785575502233da8de28e6c92f7..57f4330fc804374a778c0c55dbbfc92097e3a7f7 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <lttv/attribute.h>
 #include <ltt/ltt.h>
+#include <ltt/compiler.h>
 
 typedef union _AttributeValue {
   int dv_int;
@@ -41,7 +42,8 @@ typedef struct _Attribute {
 } Attribute;
 
 
-LttvAttributeValue address_of_value(LttvAttributeType t, AttributeValue *v)
+static __inline__ LttvAttributeValue address_of_value(LttvAttributeType t,
+                                                      AttributeValue *v)
 {
   LttvAttributeValue va;
 
@@ -176,7 +178,7 @@ lttv_attribute_remove(LttvAttribute *self, unsigned i)
   /* The element used to replace the removed element has its index entry
      all wrong now. Reinsert it with its new position. */
 
-  if(self->attributes->len != i){
+  if(likely(self->attributes->len != i)){
     g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name));
     g_hash_table_insert(self->names, GUINT_TO_POINTER(a->name), GUINT_TO_POINTER(i + 1));
   }
@@ -188,7 +190,7 @@ lttv_attribute_remove_by_name(LttvAttribute *self, LttvAttributeName name)
   unsigned i;
 
   i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
-  if(i == 0) g_error("remove by name non existent attribute");
+  if(unlikely(i == 0)) g_error("remove by name non existent attribute");
 
   lttv_attribute_remove(self, i - 1);
 }
@@ -208,9 +210,9 @@ lttv_attribute_find_subdir(LttvAttribute *self, LttvAttributeName name)
   LttvAttribute *new;
   
   i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
-  if(i != 0) {
+  if(likely(i != 0)) {
     a = g_array_index(self->attributes, Attribute, i - 1);
-    if(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject)) {
+    if(likely(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject))) {
       return LTTV_ATTRIBUTE(a.value.dv_gobject);
     }
     else return NULL;    
@@ -229,9 +231,9 @@ lttv_attribute_find(LttvAttribute *self, LttvAttributeName name,
   Attribute *a;
 
   i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
-  if(i != 0) {
+  if(likely(i != 0)) {
     a = &g_array_index(self->attributes, Attribute, i - 1);
-    if(a->type != t) return FALSE;
+    if(unlikely(a->type != t)) return FALSE;
     *v = address_of_value(t, &(a->value));
     return TRUE;
   }
@@ -514,12 +516,12 @@ attribute_interface_init (gpointer g_iface, gpointer iface_data)
 
 }
 
-
 static void
 attribute_instance_init (GTypeInstance *instance, gpointer g_class)
 {
   LttvAttribute *self = (LttvAttribute *)instance;
-  self->names = g_hash_table_new(g_direct_hash, g_direct_equal);
+  self->names = g_hash_table_new(g_direct_hash,
+                                 g_direct_equal);
   self->attributes = g_array_new(FALSE, FALSE, sizeof(Attribute));
 }
 
This page took 0.024403 seconds and 4 git commands to generate.