[list-model] Use an internal iterator for comparisons

In order to carry out various comparisons for e.g. identifying the first
iterator in the model we need a ClutterModelIter. This change switches from
creating a new iterator each time to reusing an existing iterator.
This commit is contained in:
Rob Bradford 2009-05-05 19:39:26 +01:00
parent 353187ce49
commit b2fbc2c95c

View File

@ -81,6 +81,8 @@ typedef struct _ClutterModelIterClass ClutterListModelIterClass;
struct _ClutterListModelPrivate struct _ClutterListModelPrivate
{ {
GSequence *sequence; GSequence *sequence;
ClutterModelIter *temp_iter;
}; };
struct _ClutterListModelIter struct _ClutterListModelIter
@ -225,9 +227,7 @@ clutter_list_model_iter_is_first (ClutterModelIter *iter)
begin = g_sequence_get_begin_iter (sequence); begin = g_sequence_get_begin_iter (sequence);
end = iter_default->seq_iter; end = iter_default->seq_iter;
temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER, temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
"model", model,
NULL);
while (!g_sequence_iter_is_begin (begin)) while (!g_sequence_iter_is_begin (begin))
{ {
@ -242,8 +242,6 @@ clutter_list_model_iter_is_first (ClutterModelIter *iter)
begin = g_sequence_iter_next (begin); begin = g_sequence_iter_next (begin);
} }
g_object_unref (temp_iter);
/* This is because the 'begin_iter' is always *before* the last valid /* This is because the 'begin_iter' is always *before* the last valid
* iter, otherwise we'd have endless loops * iter, otherwise we'd have endless loops
*/ */
@ -275,9 +273,7 @@ clutter_list_model_iter_is_last (ClutterModelIter *iter)
begin = g_sequence_iter_prev (begin); begin = g_sequence_iter_prev (begin);
end = iter_default->seq_iter; end = iter_default->seq_iter;
temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER, temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
"model", model,
NULL);
while (!g_sequence_iter_is_begin (begin)) while (!g_sequence_iter_is_begin (begin))
{ {
@ -292,8 +288,6 @@ clutter_list_model_iter_is_last (ClutterModelIter *iter)
begin = g_sequence_iter_prev (begin); begin = g_sequence_iter_prev (begin);
} }
g_object_unref (temp_iter);
/* This is because the 'end_iter' is always *after* the last valid iter. /* This is because the 'end_iter' is always *after* the last valid iter.
* Otherwise we'd have endless loops * Otherwise we'd have endless loops
*/ */
@ -320,9 +314,7 @@ clutter_list_model_iter_next (ClutterModelIter *iter)
filter_next = g_sequence_iter_next (iter_default->seq_iter); filter_next = g_sequence_iter_next (iter_default->seq_iter);
g_assert (filter_next != NULL); g_assert (filter_next != NULL);
temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER, temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
"model", model,
NULL);
while (!g_sequence_iter_is_end (filter_next)) while (!g_sequence_iter_is_end (filter_next))
{ {
@ -337,8 +329,6 @@ clutter_list_model_iter_next (ClutterModelIter *iter)
filter_next = g_sequence_iter_next (filter_next); filter_next = g_sequence_iter_next (filter_next);
} }
g_object_unref (temp_iter);
if (g_sequence_iter_is_end (filter_next)) if (g_sequence_iter_is_end (filter_next))
row += 1; row += 1;
@ -367,9 +357,7 @@ clutter_list_model_iter_prev (ClutterModelIter *iter)
filter_prev = g_sequence_iter_prev (iter_default->seq_iter); filter_prev = g_sequence_iter_prev (iter_default->seq_iter);
g_assert (filter_prev != NULL); g_assert (filter_prev != NULL);
temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER, temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;
"model", model,
NULL);
while (!g_sequence_iter_is_begin (filter_prev)) while (!g_sequence_iter_is_begin (filter_prev))
{ {
@ -384,8 +372,6 @@ clutter_list_model_iter_prev (ClutterModelIter *iter)
filter_prev = g_sequence_iter_prev (filter_prev); filter_prev = g_sequence_iter_prev (filter_prev);
} }
g_object_unref (temp_iter);
if (g_sequence_iter_is_begin (filter_prev)) if (g_sequence_iter_is_begin (filter_prev))
row -= 1; row -= 1;
@ -683,6 +669,20 @@ clutter_list_model_finalize (GObject *gobject)
G_OBJECT_CLASS (clutter_list_model_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_list_model_parent_class)->finalize (gobject);
} }
static void
clutter_list_model_dispose (GObject *gobject)
{
ClutterListModel *model = CLUTTER_LIST_MODEL (gobject);
if (model->priv->temp_iter)
{
g_object_unref (model->priv->temp_iter);
model->priv->temp_iter = NULL;
}
G_OBJECT_CLASS (clutter_list_model_parent_class)->finalize (gobject);
}
static void static void
clutter_list_model_class_init (ClutterListModelClass *klass) clutter_list_model_class_init (ClutterListModelClass *klass)
{ {
@ -692,6 +692,7 @@ clutter_list_model_class_init (ClutterListModelClass *klass)
g_type_class_add_private (klass, sizeof (ClutterListModelPrivate)); g_type_class_add_private (klass, sizeof (ClutterListModelPrivate));
gobject_class->finalize = clutter_list_model_finalize; gobject_class->finalize = clutter_list_model_finalize;
gobject_class->dispose = clutter_list_model_dispose;
model_class->get_iter_at_row = clutter_list_model_get_iter_at_row; model_class->get_iter_at_row = clutter_list_model_get_iter_at_row;
model_class->insert_row = clutter_list_model_insert_row; model_class->insert_row = clutter_list_model_insert_row;
@ -707,6 +708,10 @@ clutter_list_model_init (ClutterListModel *model)
model->priv = CLUTTER_LIST_MODEL_GET_PRIVATE (model); model->priv = CLUTTER_LIST_MODEL_GET_PRIVATE (model);
model->priv->sequence = g_sequence_new (NULL); model->priv->sequence = g_sequence_new (NULL);
model->priv->temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
"model",
model,
NULL);
} }
/** /**