[glib/glib-2-28] GArray: Avoid unncessary atomic accesses to refcounts



commit 1fe2fcf360a05e65878a75cd1f79a717964616a9
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 28 21:41:08 2011 -0400

    GArray: Avoid unncessary atomic accesses to refcounts
    
    Not really necessary to double-check the ref-count.

 glib/garray.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index e3d872b..80cee56 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -218,8 +218,9 @@ g_array_ref (GArray *array)
 {
   GRealArray *rarray = (GRealArray*) array;
   g_return_val_if_fail (array, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&rarray->ref_count) > 0, array);
+
   g_atomic_int_inc (&rarray->ref_count);
+
   return array;
 }
 
@@ -239,7 +240,7 @@ g_array_unref (GArray *array)
 {
   GRealArray *rarray = (GRealArray*) array;
   g_return_if_fail (array);
-  g_return_if_fail (g_atomic_int_get (&rarray->ref_count) > 0);
+
   if (g_atomic_int_dec_and_test (&rarray->ref_count))
     g_array_free (array, TRUE);
 }
@@ -872,8 +873,9 @@ g_ptr_array_ref (GPtrArray *array)
   GRealPtrArray *rarray = (GRealPtrArray*) array;
 
   g_return_val_if_fail (array, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&rarray->ref_count) > 0, array);
+
   g_atomic_int_inc (&rarray->ref_count);
+
   return array;
 }
 
@@ -892,9 +894,8 @@ void
 g_ptr_array_unref (GPtrArray *array)
 {
   GRealPtrArray *rarray = (GRealPtrArray*) array;
-
   g_return_if_fail (array);
-  g_return_if_fail (g_atomic_int_get (&rarray->ref_count) > 0);
+
   if (g_atomic_int_dec_and_test (&rarray->ref_count))
     g_ptr_array_free (array, TRUE);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]