Commit 39909b60 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: replace GimpList's internal GList with a GQueue

so we can easily iterate in reverse order, and access the last element
in O(1). Nothing makes use of this yet.
parent 7ae81e70
......@@ -201,7 +201,7 @@ tool_options_actions_update_presets (GimpActionGroup *group,
entry.value_variable = FALSE;
entry.help_id = help_id;
for (list = GIMP_LIST (presets)->list, i = 0;
for (list = GIMP_LIST (presets)->queue->head, i = 0;
list;
list = g_list_next (list), i++)
{
......
......@@ -222,7 +222,7 @@ windows_actions_setup (GimpActionGroup *group)
G_CALLBACK (windows_actions_recent_remove),
group, 0);
for (list = GIMP_LIST (global_recent_docks)->list;
for (list = GIMP_LIST (global_recent_docks)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -124,7 +124,7 @@ gimp_templates_migrate_get_child_by_name (const GimpContainer *container,
GimpObject *retval = NULL;
GList *glist;
for (glist = list->list; glist; glist = g_list_next (glist))
for (glist = list->queue->head; glist; glist = g_list_next (glist))
{
GimpObject *object = glist->data;
gchar *str1 = g_ascii_strdown (gimp_object_get_name (object), -1);
......
......@@ -1233,7 +1233,7 @@ gimp_get_image_iter (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return GIMP_LIST (gimp->images)->list;
return GIMP_LIST (gimp->images)->queue->head;
}
GList *
......@@ -1241,7 +1241,7 @@ gimp_get_display_iter (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return GIMP_LIST (gimp->displays)->list;
return GIMP_LIST (gimp->displays)->queue->head;
}
GList *
......@@ -1257,7 +1257,7 @@ gimp_get_paint_info_iter (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return GIMP_LIST (gimp->paint_info_list)->list;
return GIMP_LIST (gimp->paint_info_list)->queue->head;
}
GList *
......@@ -1265,7 +1265,7 @@ gimp_get_tool_info_iter (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return GIMP_LIST (gimp->tool_info_list)->list;
return GIMP_LIST (gimp->tool_info_list)->queue->head;
}
void
......
......@@ -318,7 +318,7 @@ gimp_data_factory_data_foreach (GimpDataFactory *factory,
GimpDataForeachFunc callback,
gpointer user_data)
{
GList *list = GIMP_LIST (factory->priv->container)->list;
GList *list = GIMP_LIST (factory->priv->container)->queue->head;
if (skip_internal)
{
......@@ -427,7 +427,7 @@ gimp_data_factory_data_save (GimpDataFactory *factory)
if (gimp_container_is_empty (factory->priv->container))
return;
for (list = GIMP_LIST (factory->priv->container)->list;
for (list = GIMP_LIST (factory->priv->container)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -277,7 +277,7 @@ gimp_filtered_container_real_src_thaw (GimpFilteredContainer *filtered_container
{
GList *list;
for (list = GIMP_LIST (filtered_container->src_container)->list;
for (list = GIMP_LIST (filtered_container->src_container)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -224,7 +224,7 @@ gimp_filter_stack_get_graph (GimpFilterStack *stack)
if (stack->graph)
return stack->graph;
for (list = GIMP_LIST (stack)->list;
for (list = GIMP_LIST (stack)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -815,7 +815,7 @@ gimp_item_get_container_iter (GimpItem *item)
container = gimp_item_get_container (item);
if (container)
return GIMP_LIST (container)->list;
return GIMP_LIST (container)->queue->head;
return NULL;
}
......
......@@ -118,7 +118,7 @@ gimp_item_stack_get_n_items (GimpItemStack *stack)
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), 0);
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
for (list = GIMP_LIST (stack)->queue->head; list; list = g_list_next (list))
{
GimpItem *item = list->data;
GimpContainer *children;
......@@ -141,7 +141,7 @@ gimp_item_stack_is_flat (GimpItemStack *stack)
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), TRUE);
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
for (list = GIMP_LIST (stack)->queue->head; list; list = g_list_next (list))
{
GimpViewable *viewable = list->data;
......@@ -157,7 +157,7 @@ gimp_item_stack_get_item_iter (GimpItemStack *stack)
{
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
return GIMP_LIST (stack)->list;
return GIMP_LIST (stack)->queue->head;
}
GList *
......@@ -168,7 +168,7 @@ gimp_item_stack_get_item_list (GimpItemStack *stack)
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
for (list = GIMP_LIST (stack)->list;
for (list = GIMP_LIST (stack)->queue->head;
list;
list = g_list_next (list))
{
......@@ -205,7 +205,7 @@ gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
for (list = GIMP_LIST (stack)->queue->head; list; list = g_list_next (list))
{
GimpItem *item = list->data;
GimpContainer *children;
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimplist.c
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2001-2016 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -27,6 +27,7 @@
#include "core-types.h"
#include "gimp-memsize.h"
#include "gimplist.h"
......@@ -39,6 +40,7 @@ enum
};
static void gimp_list_finalize (GObject *object);
static void gimp_list_set_property (GObject *object,
guint property_id,
const GValue *value,
......@@ -89,6 +91,7 @@ gimp_list_class_init (GimpListClass *klass)
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass);
object_class->finalize = gimp_list_finalize;
object_class->set_property = gimp_list_set_property;
object_class->get_property = gimp_list_get_property;
......@@ -128,12 +131,26 @@ gimp_list_class_init (GimpListClass *klass)
static void
gimp_list_init (GimpList *list)
{
list->list = NULL;
list->queue = g_queue_new ();
list->unique_names = FALSE;
list->sort_func = NULL;
list->append = FALSE;
}
static void
gimp_list_finalize (GObject *object)
{
GimpList *list = GIMP_LIST (object);
if (list->queue)
{
g_queue_free (list->queue);
list->queue = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_list_set_property (GObject *object,
guint property_id,
......@@ -193,22 +210,32 @@ gimp_list_get_memsize (GimpObject *object,
GimpList *list = GIMP_LIST (object);
gint64 memsize = 0;
memsize += (gimp_container_get_n_children (GIMP_CONTAINER (list)) *
sizeof (GList));
if (gimp_container_get_policy (GIMP_CONTAINER (list)) ==
GIMP_CONTAINER_POLICY_STRONG)
{
GList *glist;
for (glist = list->list; glist; glist = g_list_next (glist))
memsize += gimp_object_get_memsize (GIMP_OBJECT (glist->data), gui_size);
memsize += gimp_g_queue_get_memsize_foreach (list->queue,
(GimpMemsizeFunc) gimp_object_get_memsize,
gui_size);
}
else
{
memsize += gimp_g_queue_get_memsize (list->queue, 0);
}
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static gint
gimp_list_sort_func (gconstpointer a,
gconstpointer b,
gpointer user_data)
{
GCompareFunc func = user_data;
return func (a, b);
}
static void
gimp_list_add (GimpContainer *container,
GimpObject *object)
......@@ -224,11 +251,18 @@ gimp_list_add (GimpContainer *container,
list);
if (list->sort_func)
list->list = g_list_insert_sorted (list->list, object, list->sort_func);
{
g_queue_insert_sorted (list->queue, object, gimp_list_sort_func,
list->sort_func);
}
else if (list->append)
list->list = g_list_append (list->list, object);
{
g_queue_push_tail (list->queue, object);
}
else
list->list = g_list_prepend (list->list, object);
{
g_queue_push_head (list->queue, object);
}
GIMP_CONTAINER_CLASS (parent_class)->add (container, object);
}
......@@ -244,7 +278,7 @@ gimp_list_remove (GimpContainer *container,
gimp_list_object_renamed,
list);
list->list = g_list_remove (list->list, object);
g_queue_remove (list->queue, object);
GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
}
......@@ -256,12 +290,12 @@ gimp_list_reorder (GimpContainer *container,
{
GimpList *list = GIMP_LIST (container);
list->list = g_list_remove (list->list, object);
g_queue_remove (list->queue, object);
if (new_index == gimp_container_get_n_children (container) - 1)
list->list = g_list_append (list->list, object);
g_queue_push_tail (list->queue, object);
else
list->list = g_list_insert (list->list, object, new_index);
g_queue_push_nth (list->queue, object, new_index);
}
static void
......@@ -269,8 +303,8 @@ gimp_list_clear (GimpContainer *container)
{
GimpList *list = GIMP_LIST (container);
while (list->list)
gimp_container_remove (container, list->list->data);
while (g_queue_peek_head (list->queue))
gimp_container_remove (container, g_queue_peek_head (list->queue));
}
static gboolean
......@@ -279,7 +313,7 @@ gimp_list_have (const GimpContainer *container,
{
GimpList *list = GIMP_LIST (container);
return g_list_find (list->list, object) ? TRUE : FALSE;
return g_queue_find (list->queue, object) ? TRUE : FALSE;
}
static void
......@@ -289,7 +323,7 @@ gimp_list_foreach (const GimpContainer *container,
{
GimpList *list = GIMP_LIST (container);
g_list_foreach (list->list, func, user_data);
g_queue_foreach (list->queue, func, user_data);
}
static GimpObject *
......@@ -299,7 +333,7 @@ gimp_list_get_child_by_name (const GimpContainer *container,
GimpList *list = GIMP_LIST (container);
GList *glist;
for (glist = list->list; glist; glist = g_list_next (glist))
for (glist = list->queue->head; glist; glist = g_list_next (glist))
{
GimpObject *object = glist->data;
......@@ -315,14 +349,8 @@ gimp_list_get_child_by_index (const GimpContainer *container,
gint index)
{
GimpList *list = GIMP_LIST (container);
GList *glist;
glist = g_list_nth (list->list, index);
if (glist)
return (GimpObject *) glist->data;
return NULL;
return g_queue_peek_nth (list->queue, index);
}
static gint
......@@ -331,7 +359,7 @@ gimp_list_get_child_index (const GimpContainer *container,
{
GimpList *list = GIMP_LIST (container);
return g_list_index (list->list, (gpointer) object);
return g_queue_index (list->queue, (gpointer) object);
}
/**
......@@ -416,7 +444,7 @@ gimp_list_reverse (GimpList *list)
if (gimp_container_get_n_children (GIMP_CONTAINER (list)) > 1)
{
gimp_container_freeze (GIMP_CONTAINER (list));
list->list = g_list_reverse (list->list);
g_queue_reverse (list->queue);
gimp_container_thaw (GIMP_CONTAINER (list));
}
}
......@@ -480,7 +508,7 @@ gimp_list_sort (GimpList *list,
if (gimp_container_get_n_children (GIMP_CONTAINER (list)) > 1)
{
gimp_container_freeze (GIMP_CONTAINER (list));
list->list = g_list_sort (list->list, sort_func);
g_queue_sort (list->queue, gimp_list_sort_func, sort_func);
gimp_container_thaw (GIMP_CONTAINER (list));
}
}
......@@ -512,7 +540,7 @@ gimp_list_uniquefy_name (GimpList *gimp_list,
if (! name)
return;
for (list = gimp_list->list; list; list = g_list_next (list))
for (list = gimp_list->queue->head; list; list = g_list_next (list))
{
GimpObject *object2 = list->data;
const gchar *name2 = gimp_object_get_name (object2);
......@@ -563,7 +591,7 @@ gimp_list_uniquefy_name (GimpList *gimp_list,
new_name = g_strdup_printf ("%s #%d", name, unique_ext);
for (list = gimp_list->list; list; list = g_list_next (list))
for (list = gimp_list->queue->head; list; list = g_list_next (list))
{
GimpObject *object2 = list->data;
const gchar *name2 = gimp_object_get_name (object2);
......@@ -605,9 +633,9 @@ gimp_list_object_renamed (GimpObject *object,
gint old_index;
gint new_index = 0;
old_index = g_list_index (list->list, object);
old_index = g_queue_index (list->queue, object);
for (glist = list->list; glist; glist = g_list_next (glist))
for (glist = list->queue->head; glist; glist = g_list_next (glist))
{
GimpObject *object2 = GIMP_OBJECT (glist->data);
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimplist.h
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2001-2016 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -39,7 +39,7 @@ struct _GimpList
{
GimpContainer parent_instance;
GList *list;
GQueue *queue;
gboolean unique_names;
GCompareFunc sort_func;
gboolean append;
......
......@@ -156,7 +156,7 @@ gimp_tagged_container_clear (GimpContainer *container)
GimpTaggedContainer *tagged_container = GIMP_TAGGED_CONTAINER (container);
GList *list;
for (list = GIMP_LIST (filtered_container->src_container)->list;
for (list = GIMP_LIST (filtered_container->src_container)->queue->head;
list;
list = g_list_next (list))
{
......@@ -242,7 +242,7 @@ gimp_tagged_container_src_thaw (GimpFilteredContainer *filtered_container)
{
GList *list;
for (list = GIMP_LIST (filtered_container->src_container)->list;
for (list = GIMP_LIST (filtered_container->src_container)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -101,7 +101,7 @@ gimp_undo_stack_pop (GimpUndo *undo,
GimpUndoStack *stack = GIMP_UNDO_STACK (undo);
GList *list;
for (list = GIMP_LIST (stack->undos)->list;
for (list = GIMP_LIST (stack->undos)->queue->head;
list;
list = g_list_next (list))
{
......@@ -118,7 +118,7 @@ gimp_undo_stack_free (GimpUndo *undo,
GimpUndoStack *stack = GIMP_UNDO_STACK (undo);
GList *list;
for (list = GIMP_LIST (stack->undos)->list;
for (list = GIMP_LIST (stack->undos)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -352,7 +352,6 @@ convert_dialog_palette_box (IndexedDialog *dialog)
{
Gimp *gimp = dialog->image->gimp;
GList *list;
GimpPalette *palette;
GimpPalette *web_palette = NULL;
gboolean default_found = FALSE;
......@@ -376,11 +375,11 @@ convert_dialog_palette_box (IndexedDialog *dialog)
g_object_weak_ref (G_OBJECT (dialog->dialog),
(GWeakNotify) g_object_unref, dialog->container);
for (list = GIMP_LIST (dialog->container)->list;
for (list = GIMP_LIST (dialog->container)->queue->head;
list;
list = g_list_next (list))
{
palette = list->data;
GimpPalette *palette = list->data;
/* Preferentially, the initial default is 'Web' if available */
if (web_palette == NULL &&
......@@ -401,7 +400,7 @@ convert_dialog_palette_box (IndexedDialog *dialog)
if (web_palette)
dialog->custom_palette = web_palette;
else
dialog->custom_palette = GIMP_LIST (dialog->container)->list->data;
dialog->custom_palette = GIMP_LIST (dialog->container)->queue->head->data;
}
gimp_context_set_palette (dialog->context, dialog->custom_palette);
......
......@@ -139,7 +139,7 @@ windows_menu_setup (GimpUIManager *manager,
G_CALLBACK (windows_menu_recent_remove),
manager, 0);
for (list = g_list_last (GIMP_LIST (global_recent_docks)->list);
for (list = g_list_last (GIMP_LIST (global_recent_docks)->queue->head);
list;
list = g_list_previous (list))
{
......
......@@ -409,7 +409,7 @@ gimp_pdb_context_reset (GimpConfig *config)
GimpPDBContext *context = GIMP_PDB_CONTEXT (config);
GList *list;
for (list = GIMP_LIST (context->paint_options_list)->list;
for (list = GIMP_LIST (context->paint_options_list)->queue->head;
list;
list = g_list_next (list))
{
......@@ -462,7 +462,7 @@ gimp_pdb_context_new (Gimp *gimp,
}
else
{
for (list = GIMP_LIST (GIMP_PDB_CONTEXT (parent)->paint_options_list)->list;
for (list = GIMP_LIST (GIMP_PDB_CONTEXT (parent)->paint_options_list)->queue->head;
list;
list = g_list_next (list))
{
......@@ -508,7 +508,7 @@ gimp_pdb_context_get_brush_options (GimpPDBContext *context)
g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
for (list = GIMP_LIST (context->paint_options_list)->list;
for (list = GIMP_LIST (context->paint_options_list)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -419,7 +419,7 @@ item_get_children_invoker (GimpProcedure *procedure,
child_ids = g_new (gint32, num_children);
for (list = GIMP_LIST (children)->list, i = 0;
for (list = GIMP_LIST (children)->queue->head, i = 0;
list;
list = g_list_next (list), i++)
{
......
......@@ -279,7 +279,7 @@ gimp_tools_restore (Gimp *gimp)
gimp_list_reverse (GIMP_LIST (gimp_list));
for (list = GIMP_LIST (gimp_list)->list, i = 0;
for (list = GIMP_LIST (gimp_list)->queue->head, i = 0;
list;
list = g_list_next (list), i++)
{
......
......@@ -246,7 +246,7 @@ gimp_device_editor_constructed (GObject *object)
G_CALLBACK (gimp_device_editor_device_changed),
editor);
for (list = GIMP_LIST (devices)->list;
for (list = GIMP_LIST (devices)->queue->head;
list;
list = g_list_next (list))
{
......
......@@ -99,7 +99,7 @@ gimp_devices_restore (Gimp *gimp)
user_context = gimp_get_user_context (gimp);
for (list = GIMP_LIST (manager)->list;
for (list = GIMP_LIST (manager)->queue->head;
list;
list = g_list_next (list))
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment