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
This commit is contained in:
Garrett Regier 2015-06-03 17:15:17 -07:00
parent 36593a3aba
commit ace7f6861e

View File

@ -240,9 +240,11 @@ weak_unbind (gpointer user_data,
g_object_unref (binding); g_object_unref (binding);
} }
static inline gboolean static gboolean
default_transform (const GValue *value_a, default_transform (GBinding *binding,
GValue *value_b) 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 /* if it's not the same type, try to convert it using the GValue
* transformation API; otherwise just copy it * transformation API; otherwise just copy it
@ -279,9 +281,11 @@ done:
return TRUE; return TRUE;
} }
static inline gboolean static gboolean
default_invert_boolean_transform (const GValue *value_a, default_invert_boolean_transform (GBinding *binding,
GValue *value_b) const GValue *value_a,
GValue *value_b,
gpointer user_data G_GNUC_UNUSED)
{ {
gboolean value; gboolean value;
@ -296,30 +300,6 @@ default_invert_boolean_transform (const GValue *value_a,
return TRUE; 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 static void
on_source_notify (GObject *gobject, on_source_notify (GObject *gobject,
GParamSpec *pspec, GParamSpec *pspec,
@ -518,6 +498,7 @@ static void
g_binding_constructed (GObject *gobject) g_binding_constructed (GObject *gobject)
{ {
GBinding *binding = G_BINDING (gobject); GBinding *binding = G_BINDING (gobject);
GBindingTransformFunc transform_func = default_transform;
GQuark source_property_detail; GQuark source_property_detail;
GClosure *source_notify_closure; GClosure *source_notify_closure;
@ -536,9 +517,13 @@ g_binding_constructed (GObject *gobject)
g_assert (binding->source_pspec != NULL); g_assert (binding->source_pspec != NULL);
g_assert (binding->target_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 */ /* set the default transformation functions here */
binding->transform_s2t = default_transform_to; binding->transform_s2t = transform_func;
binding->transform_t2s = default_transform_from; binding->transform_t2s = transform_func;
binding->transform_data = NULL; binding->transform_data = NULL;
binding->notify = NULL; binding->notify = NULL;