Use the slice allocater for GtkTreeDataSortHeader.

2005-12-29  Matthias Clasen  <mclasen@redhat.com>

	* 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.
This commit is contained in:
Matthias Clasen 2005-12-29 05:26:09 +00:00 committed by Matthias Clasen
parent c63a3dccab
commit 4cb44fcc8f
7 changed files with 95 additions and 103 deletions

View File

@ -1,3 +1,15 @@
2005-12-29 Matthias Clasen <mclasen@redhat.com>
* 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 <mclasen@redhat.com>
* gtk/gtkbindings.h (GtkBindingSignal):

View File

@ -1,3 +1,15 @@
2005-12-29 Matthias Clasen <mclasen@redhat.com>
* 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 <mclasen@redhat.com>
* gtk/gtkbindings.h (GtkBindingSignal):

View File

@ -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);

View File

@ -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,7 +490,7 @@ _gtk_tree_data_list_header_free (GList *list)
d (header->data);
}
g_free (header);
g_slice_free (GtkTreeDataSortHeader, header);
}
g_list_free (list);
}
@ -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;
}

View File

@ -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__ */

View File

@ -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);

View File

@ -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);