model: Clean up ModelIter vfunc wrappers

All ClutterModelIter virtual functions have a default implementation,
and G_TYPE_INSTANCE_GET_CLASS cannot return NULL unless in case of a
catastrophic event in the type system - which will most likely blow up
any application code way before you could call a ModelIter method.

Thus, the idiom:

  klass = CLUTTER_MODEL_ITER_GET_CLASS (instance);
  if (klass && klass->vfunc)
    klass->vfunc (instance);

is utterly useless complication, and it can be perfectly replaced by:

  CLUTTER_MODEL_ITER_GET_CLASS (instance)->vfunc (instance);

without any loss of safety.
This commit is contained in:
Emmanuele Bassi 2011-07-29 11:29:51 +01:00
parent e470fd7d82
commit 473f3817d4

View File

@ -1761,8 +1761,6 @@ struct _ClutterModelIterPrivate
ClutterModel *model; ClutterModel *model;
gint row; gint row;
guint ignore_sort : 1;
}; };
enum enum
@ -1972,8 +1970,6 @@ clutter_model_iter_init (ClutterModelIter *self)
priv->model = NULL; priv->model = NULL;
priv->row = 0; priv->row = 0;
priv->ignore_sort = FALSE;
} }
/* /*
@ -1985,11 +1981,7 @@ clutter_model_iter_set_value_internal (ClutterModelIter *iter,
guint column, guint column,
const GValue *value) const GValue *value)
{ {
ClutterModelIterClass *klass; CLUTTER_MODEL_ITER_GET_CLASS (iter)->set_value (iter, column, value);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter);
if (klass && klass->set_value)
klass->set_value (iter, column, value);
} }
static void static void
@ -2005,9 +1997,6 @@ clutter_model_iter_set_internal_valist (ClutterModelIter *iter,
column = va_arg (args, gint); column = va_arg (args, gint);
/* Don't want to sort while setting lots of fields, leave that till the end
*/
priv->ignore_sort = TRUE;
while (column != -1) while (column != -1)
{ {
GValue value = { 0, }; GValue value = { 0, };
@ -2044,7 +2033,6 @@ clutter_model_iter_set_internal_valist (ClutterModelIter *iter,
column = va_arg (args, gint); column = va_arg (args, gint);
} }
priv->ignore_sort = FALSE;
if (sort) if (sort)
clutter_model_resort (model); clutter_model_resort (model);
} }
@ -2113,6 +2101,14 @@ clutter_model_iter_get (ClutterModelIter *iter,
va_end (args); va_end (args);
} }
static inline void
clutter_model_iter_get_value_internal (ClutterModelIter *iter,
guint column,
GValue *value)
{
CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_value (iter, column, value);
}
/** /**
* clutter_model_iter_get_value: * clutter_model_iter_get_value:
* @iter: a #ClutterModelIter * @iter: a #ClutterModelIter
@ -2136,11 +2132,10 @@ clutter_model_iter_get_value (ClutterModelIter *iter,
model = iter->priv->model; model = iter->priv->model;
g_value_init (value, clutter_model_get_column_type (model, column)); if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
g_value_init (value, clutter_model_get_column_type (model, column));
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_value (iter, column, value);
if (klass && klass->get_value)
klass->get_value (iter, column, value);
} }
/** /**
@ -2173,6 +2168,7 @@ clutter_model_iter_get_valist (ClutterModelIter *iter,
{ {
GValue value = { 0, }; GValue value = { 0, };
gchar *error = NULL; gchar *error = NULL;
GType col_type;
if (column < 0 || column >= clutter_model_get_n_columns (model)) if (column < 0 || column >= clutter_model_get_n_columns (model))
{ {
@ -2182,10 +2178,10 @@ clutter_model_iter_get_valist (ClutterModelIter *iter,
break; break;
} }
/* this one will take care of initialising value to the col_type = clutter_model_get_column_type (model, column);
* correct type g_value_init (&value, col_type);
*/
clutter_model_iter_get_value (iter, column, &value); clutter_model_iter_get_value_internal (iter, column, &value);
G_VALUE_LCOPY (&value, args, 0, &error); G_VALUE_LCOPY (&value, args, 0, &error);
if (error) if (error)
@ -2270,15 +2266,9 @@ clutter_model_iter_set_value (ClutterModelIter *iter,
gboolean gboolean
clutter_model_iter_is_first (ClutterModelIter *iter) clutter_model_iter_is_first (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), FALSE); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), FALSE);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->is_first (iter);
if (klass && klass->is_first)
return klass->is_first (iter);
return FALSE;
} }
/** /**
@ -2295,15 +2285,9 @@ clutter_model_iter_is_first (ClutterModelIter *iter)
gboolean gboolean
clutter_model_iter_is_last (ClutterModelIter *iter) clutter_model_iter_is_last (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), FALSE); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), FALSE);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->is_last (iter);
if (klass && klass->is_last)
return klass->is_last (iter);
return FALSE;
} }
/** /**
@ -2322,15 +2306,9 @@ clutter_model_iter_is_last (ClutterModelIter *iter)
ClutterModelIter * ClutterModelIter *
clutter_model_iter_next (ClutterModelIter *iter) clutter_model_iter_next (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->next (iter);
if (klass && klass->next)
return klass->next (iter);
return NULL;
} }
/** /**
@ -2349,15 +2327,9 @@ clutter_model_iter_next (ClutterModelIter *iter)
ClutterModelIter * ClutterModelIter *
clutter_model_iter_prev (ClutterModelIter *iter) clutter_model_iter_prev (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->prev (iter);
if (klass && klass->prev)
return klass->prev (iter);
return NULL;
} }
/** /**
@ -2373,15 +2345,9 @@ clutter_model_iter_prev (ClutterModelIter *iter)
ClutterModel * ClutterModel *
clutter_model_iter_get_model (ClutterModelIter *iter) clutter_model_iter_get_model (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_model (iter);
if (klass && klass->get_model)
return klass->get_model (iter);
return NULL;
} }
/** /**
@ -2397,15 +2363,9 @@ clutter_model_iter_get_model (ClutterModelIter *iter)
guint guint
clutter_model_iter_get_row (ClutterModelIter *iter) clutter_model_iter_get_row (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), 0); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), 0);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_row (iter);
if (klass && klass->get_row)
return klass->get_row (iter);
return 0;
} }
/** /**
@ -2421,13 +2381,7 @@ clutter_model_iter_get_row (ClutterModelIter *iter)
ClutterModelIter * ClutterModelIter *
clutter_model_iter_copy (ClutterModelIter *iter) clutter_model_iter_copy (ClutterModelIter *iter)
{ {
ClutterModelIterClass *klass;
g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL); g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
klass = CLUTTER_MODEL_ITER_GET_CLASS (iter); return CLUTTER_MODEL_ITER_GET_CLASS (iter)->copy (iter);
if (klass->copy)
return klass->copy (iter);
return NULL;
} }