[glib] binding: Remove conditional from the default transform function



commit ace7f6861e180d8a9a3b6982e2cfa522cb0cb5a0
Author: Garrett Regier <garrettregier gmail com>
Date:   Wed Jun 3 17:15:17 2015 -0700

    binding: Remove conditional from the default transform function
    
    Avoiding checking for INVERT_BOOLEAN each and
    instead choose the correct function in constructed().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=750369

 gobject/gbinding.c |   49 +++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 32 deletions(-)
---
diff --git a/gobject/gbinding.c b/gobject/gbinding.c
index d22dde1..f9db9c5 100644
--- a/gobject/gbinding.c
+++ b/gobject/gbinding.c
@@ -240,9 +240,11 @@ weak_unbind (gpointer  user_data,
   g_object_unref (binding);
 }
 
-static inline gboolean
-default_transform (const GValue *value_a,
-                   GValue       *value_b)
+static gboolean
+default_transform (GBinding     *binding,
+                   const GValue *value_a,
+                   GValue       *value_b,
+                   gpointer      user_data G_GNUC_UNUSED)
 {
   /* if it's not the same type, try to convert it using the GValue
    * transformation API; otherwise just copy it
@@ -279,9 +281,11 @@ done:
   return TRUE;
 }
 
-static inline gboolean
-default_invert_boolean_transform (const GValue *value_a,
-                                  GValue       *value_b)
+static gboolean
+default_invert_boolean_transform (GBinding     *binding,
+                                  const GValue *value_a,
+                                  GValue       *value_b,
+                                  gpointer      user_data G_GNUC_UNUSED)
 {
   gboolean value;
 
@@ -296,30 +300,6 @@ default_invert_boolean_transform (const GValue *value_a,
   return TRUE;
 }
 
-static gboolean
-default_transform_to (GBinding     *binding,
-                      const GValue *value_a,
-                      GValue       *value_b,
-                      gpointer      user_data G_GNUC_UNUSED)
-{
-  if (binding->flags & G_BINDING_INVERT_BOOLEAN)
-    return default_invert_boolean_transform (value_a, value_b);
-
-  return default_transform (value_a, value_b);
-}
-
-static gboolean
-default_transform_from (GBinding     *binding,
-                        const GValue *value_a,
-                        GValue       *value_b,
-                        gpointer      user_data G_GNUC_UNUSED)
-{
-  if (binding->flags & G_BINDING_INVERT_BOOLEAN)
-    return default_invert_boolean_transform (value_a, value_b);
-
-  return default_transform (value_a, value_b);
-}
-
 static void
 on_source_notify (GObject    *gobject,
                   GParamSpec *pspec,
@@ -518,6 +498,7 @@ static void
 g_binding_constructed (GObject *gobject)
 {
   GBinding *binding = G_BINDING (gobject);
+  GBindingTransformFunc transform_func = default_transform;
   GQuark source_property_detail;
   GClosure *source_notify_closure;
 
@@ -536,9 +517,13 @@ g_binding_constructed (GObject *gobject)
   g_assert (binding->source_pspec != NULL);
   g_assert (binding->target_pspec != NULL);
 
+  /* switch to the invert boolean transform if needed */
+  if (binding->flags & G_BINDING_INVERT_BOOLEAN)
+    transform_func = default_invert_boolean_transform;
+
   /* set the default transformation functions here */
-  binding->transform_s2t = default_transform_to;
-  binding->transform_t2s = default_transform_from;
+  binding->transform_s2t = transform_func;
+  binding->transform_t2s = transform_func;
 
   binding->transform_data = NULL;
   binding->notify = NULL;


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