mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
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:
parent
36593a3aba
commit
ace7f6861e
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user