From 4cb44fcc8fb40694f2002fcc51b56ce23b84037e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 29 Dec 2005 05:26:09 +0000 Subject: [PATCH] Use the slice allocater for GtkTreeDataSortHeader. 2005-12-29 Matthias Clasen * gtk/gtktreedatalist.c: Use the slice allocater for GtkTreeDataSortHeader. * gtk/gtktreedatalist.h: * gtk/gtktreedatalist.c (_gtk_tree_data_list_set_header): New function. * gtk/gtktreemodelsort.c (gtk_tree_model_sort_set_sort_func): * gtk/gtkliststore.c (gtk_list_store_set_sort_func): * gtk/gtktreestore.c (gtk_tree_store_set_sort_func): Use it here. --- ChangeLog | 12 +++++++++ ChangeLog.pre-2-10 | 12 +++++++++ gtk/gtkliststore.c | 36 ++++----------------------- gtk/gtktreedatalist.c | 55 +++++++++++++++++++++++++++++++++++++++--- gtk/gtktreedatalist.h | 6 ++++- gtk/gtktreemodelsort.c | 36 +++------------------------ gtk/gtktreestore.c | 41 ++++++------------------------- 7 files changed, 95 insertions(+), 103 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d4dcff26f..f3e10223a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-12-29 Matthias Clasen + + * gtk/gtktreedatalist.c: Use the slice allocater for + GtkTreeDataSortHeader. + + * gtk/gtktreedatalist.h: + * gtk/gtktreedatalist.c (_gtk_tree_data_list_set_header): New function. + + * gtk/gtktreemodelsort.c (gtk_tree_model_sort_set_sort_func): + * gtk/gtkliststore.c (gtk_list_store_set_sort_func): + * gtk/gtktreestore.c (gtk_tree_store_set_sort_func): Use it here. + 2005-12-27 Matthias Clasen * gtk/gtkbindings.h (GtkBindingSignal): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1d4dcff26f..f3e10223a7 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2005-12-29 Matthias Clasen + + * gtk/gtktreedatalist.c: Use the slice allocater for + GtkTreeDataSortHeader. + + * gtk/gtktreedatalist.h: + * gtk/gtktreedatalist.c (_gtk_tree_data_list_set_header): New function. + + * gtk/gtktreemodelsort.c (gtk_tree_model_sort_set_sort_func): + * gtk/gtkliststore.c (gtk_list_store_set_sort_func): + * gtk/gtktreestore.c (gtk_tree_store_set_sort_func): Use it here. + 2005-12-27 Matthias Clasen * gtk/gtkbindings.h (GtkBindingSignal): diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c index 29d28fbc3b..43a6bc7142 100644 --- a/gtk/gtkliststore.c +++ b/gtk/gtkliststore.c @@ -1801,7 +1801,8 @@ gtk_list_store_set_sort_column_id (GtkTreeSortable *sortable, { GtkTreeDataSortHeader *header = NULL; - header = _gtk_tree_data_list_get_header (list_store->sort_list, sort_column_id); + header = _gtk_tree_data_list_get_header (list_store->sort_list, + sort_column_id); /* We want to make sure that we have a function */ g_return_if_fail (header != NULL); @@ -1836,36 +1837,9 @@ gtk_list_store_set_sort_func (GtkTreeSortable *sortable, g_return_if_fail (GTK_IS_LIST_STORE (sortable)); g_return_if_fail (func != NULL); - for (list = list_store->sort_list; list; list = list->next) - { - GtkTreeDataSortHeader *list_header; - - list_header = (GtkTreeDataSortHeader*) list->data; - if (list_header->sort_column_id == sort_column_id) - { - header = list_header; - break; - } - } - - if (header == NULL) - { - header = g_new0 (GtkTreeDataSortHeader, 1); - header->sort_column_id = sort_column_id; - list_store->sort_list = g_list_append (list_store->sort_list, header); - } - - if (header->destroy) - { - GtkDestroyNotify d = header->destroy; - - header->destroy = NULL; - d (header->data); - } - - header->func = func; - header->data = data; - header->destroy = destroy; + list_store->sort_list = _gtk_tree_data_list_set_header (list_store->sort_list, + sort_column_id, + func, data, destroy); if (list_store->sort_column_id == sort_column_id) gtk_list_store_sort (list_store); diff --git a/gtk/gtktreedatalist.c b/gtk/gtktreedatalist.c index 9cbd26a7aa..02040fa4cb 100644 --- a/gtk/gtktreedatalist.c +++ b/gtk/gtktreedatalist.c @@ -462,7 +462,7 @@ _gtk_tree_data_list_header_new (gint n_columns, { GtkTreeDataSortHeader *header; - header = g_new (GtkTreeDataSortHeader, 1); + header = g_slice_new (GtkTreeDataSortHeader); retval = g_list_prepend (retval, header); header->sort_column_id = i; @@ -490,14 +490,14 @@ _gtk_tree_data_list_header_free (GList *list) d (header->data); } - g_free (header); + g_slice_free (GtkTreeDataSortHeader, header); } g_list_free (list); } GtkTreeDataSortHeader * -_gtk_tree_data_list_get_header (GList *header_list, - gint sort_column_id) +_gtk_tree_data_list_get_header (GList *header_list, + gint sort_column_id) { GtkTreeDataSortHeader *header = NULL; @@ -509,3 +509,50 @@ _gtk_tree_data_list_get_header (GList *header_list, } return NULL; } + + +GList * +_gtk_tree_data_list_set_header (GList *header_list, + gint sort_column_id, + GtkTreeIterCompareFunc func, + gpointer data, + GtkDestroyNotify destroy) +{ + GList *list = header_list; + GtkTreeDataSortHeader *header = NULL; + + for (; list; list = list->next) + { + header = (GtkTreeDataSortHeader*) list->data; + if (header->sort_column_id == sort_column_id) + break; + header = NULL; + + if (list->next == NULL) + break; + } + + if (header == NULL) + { + header = g_slice_new0 (GtkTreeDataSortHeader); + header->sort_column_id = sort_column_id; + if (list) + g_list_append (list, header); + else + header_list = g_list_append (header_list, header); + } + + if (header->destroy) + { + GtkDestroyNotify d = header->destroy; + + header->destroy = NULL; + d (header->data); + } + + header->func = func; + header->data = data; + header->destroy = destroy; + + return header_list; +} diff --git a/gtk/gtktreedatalist.h b/gtk/gtktreedatalist.h index 247a33a355..49a0940f4d 100644 --- a/gtk/gtktreedatalist.h +++ b/gtk/gtktreedatalist.h @@ -76,6 +76,10 @@ GList * _gtk_tree_data_list_header_new (gint n_columns, void _gtk_tree_data_list_header_free (GList *header_list); GtkTreeDataSortHeader *_gtk_tree_data_list_get_header (GList *header_list, gint sort_column_id); - +GList *_gtk_tree_data_list_set_header (GList *header_list, + gint sort_column_id, + GtkTreeIterCompareFunc func, + gpointer data, + GtkDestroyNotify destroy); #endif /* __GTK_TREE_DATA_LIST_H__ */ diff --git a/gtk/gtktreemodelsort.c b/gtk/gtktreemodelsort.c index 20b0f53239..d7b79f76ee 100644 --- a/gtk/gtktreemodelsort.c +++ b/gtk/gtktreemodelsort.c @@ -1389,43 +1389,13 @@ gtk_tree_model_sort_set_sort_func (GtkTreeSortable *sortable, GtkDestroyNotify destroy) { GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) sortable; - GtkTreeDataSortHeader *header = NULL; - GList *list; g_return_if_fail (GTK_IS_TREE_MODEL_SORT (sortable)); g_return_if_fail (func != NULL); - for (list = tree_model_sort->sort_list; list; list = list->next) - { - GtkTreeDataSortHeader *list_header; - - list_header = (GtkTreeDataSortHeader*) list->data; - if (list_header->sort_column_id == sort_column_id) - { - header = list_header; - break; - } - } - - if (header == NULL) - { - header = g_new0 (GtkTreeDataSortHeader, 1); - header->sort_column_id = sort_column_id; - tree_model_sort->sort_list = g_list_append (tree_model_sort->sort_list, - header); - } - - if (header->destroy) - { - GtkDestroyNotify d = header->destroy; - - header->destroy = NULL; - d (header->data); - } - - header->func = func; - header->data = data; - header->destroy = destroy; + tree_model_sort->sort_list = _gtk_tree_data_list_set_header (tree_model_sort->sort_list, + sort_column_id, + func, data, destroy); if (tree_model_sort->sort_column_id == sort_column_id) gtk_tree_model_sort_sort (tree_model_sort); diff --git a/gtk/gtktreestore.c b/gtk/gtktreestore.c index 914997ad79..1569fc273e 100644 --- a/gtk/gtktreestore.c +++ b/gtk/gtktreestore.c @@ -2674,7 +2674,8 @@ gtk_tree_store_sort (GtkTreeStore *tree_store) { GtkTreeDataSortHeader *header = NULL; - header = _gtk_tree_data_list_get_header (tree_store->sort_list, tree_store->sort_column_id); + header = _gtk_tree_data_list_get_header (tree_store->sort_list, + tree_store->sort_column_id); /* We want to make sure that we have a function */ g_return_if_fail (header != NULL); @@ -2919,7 +2920,8 @@ gtk_tree_store_set_sort_column_id (GtkTreeSortable *sortable, { GtkTreeDataSortHeader *header = NULL; - header = _gtk_tree_data_list_get_header (tree_store->sort_list, sort_column_id); + header = _gtk_tree_data_list_get_header (tree_store->sort_list, + sort_column_id); /* We want to make sure that we have a function */ g_return_if_fail (header != NULL); @@ -2947,42 +2949,13 @@ gtk_tree_store_set_sort_func (GtkTreeSortable *sortable, GtkDestroyNotify destroy) { GtkTreeStore *tree_store = (GtkTreeStore *) sortable; - GtkTreeDataSortHeader *header = NULL; - GList *list; g_return_if_fail (GTK_IS_TREE_STORE (sortable)); g_return_if_fail (func != NULL); - for (list = tree_store->sort_list; list; list = list->next) - { - GtkTreeDataSortHeader *list_header; - - list_header = (GtkTreeDataSortHeader*) list->data; - if (list_header->sort_column_id == sort_column_id) - { - header = list_header; - break; - } - } - - if (header == NULL) - { - header = g_new0 (GtkTreeDataSortHeader, 1); - header->sort_column_id = sort_column_id; - tree_store->sort_list = g_list_append (tree_store->sort_list, header); - } - - if (header->destroy) - { - GtkDestroyNotify d = header->destroy; - - header->destroy = NULL; - d (header->data); - } - - header->func = func; - header->data = data; - header->destroy = destroy; + tree_store->sort_list = _gtk_tree_data_list_set_header (tree_store->sort_list, + sort_column_id, + func, data, destroy); if (tree_store->sort_column_id == sort_column_id) gtk_tree_store_sort (tree_store);