From 395b06ad8be88245d796cd17a6390ea8dd2ef841 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 5 Mar 2007 20:09:46 +0000 Subject: [PATCH] added typdef GimpMemsizeFunc. 2007-03-05 Michael Natterer * app/core/core-types.h: added typdef GimpMemsizeFunc. * app/core/gimp-utils.[ch]: added _foreach() variants of GHashTable, GList and GSList functions which take GimpMemsizeFunc callbacks. Added gimp_parasite_get_memsize(). Added "data_size" parameter to gimp_g_hash_table_get_memsize(). * app/core/gimp.c * app/core/gimppalette.c * app/core/gimpparasitelist.c * app/pdb/gimppdb.c * app/plug-in/gimppluginmanager.c: use the new functions instead of itering manually or ignoring the containers' elements. Changed callers of gimp_g_hash_table_get_memsize(). svn path=/trunk/; revision=22046 --- ChangeLog | 17 ++++++ app/core/core-types.h | 3 ++ app/core/gimp-utils.c | 91 ++++++++++++++++++++++++++++++++- app/core/gimp-utils.h | 63 ++++++++++++++--------- app/core/gimp.c | 4 +- app/core/gimppalette.c | 29 +++++++---- app/core/gimpparasitelist.c | 24 ++------- app/pdb/gimppdb.c | 33 +++++------- app/plug-in/gimppluginmanager.c | 39 ++++++++++---- 9 files changed, 215 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index f4957980f5..80d22ec25a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-03-05 Michael Natterer + + * app/core/core-types.h: added typdef GimpMemsizeFunc. + + * app/core/gimp-utils.[ch]: added _foreach() variants of + GHashTable, GList and GSList functions which take GimpMemsizeFunc + callbacks. Added gimp_parasite_get_memsize(). Added "data_size" + parameter to gimp_g_hash_table_get_memsize(). + + * app/core/gimp.c + * app/core/gimppalette.c + * app/core/gimpparasitelist.c + * app/pdb/gimppdb.c + * app/plug-in/gimppluginmanager.c: use the new functions instead + of itering manually or ignoring the containers' elements. Changed + callers of gimp_g_hash_table_get_memsize(). + 2007-03-05 Sven Neumann * plug-ins/common/colorify.c diff --git a/app/core/core-types.h b/app/core/core-types.h index fbee0e8583..d884c38261 100644 --- a/app/core/core-types.h +++ b/app/core/core-types.h @@ -173,6 +173,9 @@ typedef void (* GimpInitStatusFunc) (const gchar *text1, typedef gboolean (* GimpObjectFilterFunc) (const GimpObject *object, gpointer user_data); +typedef gint64 (* GimpMemsizeFunc) (gpointer instance, + gint64 *gui_size); + /* structs */ diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c index 127817accb..bf962ee9fb 100644 --- a/app/core/gimp-utils.c +++ b/app/core/gimp-utils.c @@ -80,13 +80,54 @@ gimp_g_object_get_memsize (GObject *object) } gint64 -gimp_g_hash_table_get_memsize (GHashTable *hash) +gimp_g_hash_table_get_memsize (GHashTable *hash, + gint64 data_size) { g_return_val_if_fail (hash != NULL, 0); return (2 * sizeof (gint) + 5 * sizeof (gpointer) + - g_hash_table_size (hash) * 3 * sizeof (gpointer)); + g_hash_table_size (hash) * (3 * sizeof (gpointer) + data_size)); +} + +typedef struct +{ + GimpMemsizeFunc func; + gint64 memsize; + gint64 gui_size; +} HashMemsize; + +static void +hash_memsize_foreach (gpointer key, + gpointer value, + HashMemsize *memsize) +{ + gint64 gui_size = 0; + + memsize->memsize += memsize->func (value, &gui_size); + memsize->gui_size += gui_size; +} + +gint64 +gimp_g_hash_table_get_memsize_foreach (GHashTable *hash, + GimpMemsizeFunc func, + gint64 *gui_size) +{ + HashMemsize memsize; + + g_return_val_if_fail (hash != NULL, 0); + g_return_val_if_fail (func != NULL, 0); + + memsize.func = func; + memsize.memsize = 0; + memsize.gui_size = 0; + + g_hash_table_foreach (hash, (GHFunc) hash_memsize_foreach, &memsize); + + if (gui_size) + *gui_size = memsize.gui_size; + + return memsize.memsize + gimp_g_hash_table_get_memsize (hash, 0); } gint64 @@ -96,6 +137,22 @@ gimp_g_slist_get_memsize (GSList *slist, return g_slist_length (slist) * (data_size + sizeof (GSList)); } +gint64 +gimp_g_slist_get_memsize_foreach (GSList *slist, + GimpMemsizeFunc func, + gint64 *gui_size) +{ + GSList *l; + gint64 memsize = 0; + + g_return_val_if_fail (func != NULL, 0); + + for (l = slist; l; l = g_slist_next (l)) + memsize += sizeof (GSList) + func (l->data, gui_size); + + return memsize; +} + gint64 gimp_g_list_get_memsize (GList *list, gint64 data_size) @@ -103,6 +160,22 @@ gimp_g_list_get_memsize (GList *list, return g_list_length (list) * (data_size + sizeof (GList)); } +gint64 +gimp_g_list_get_memsize_foreach (GList *list, + GimpMemsizeFunc func, + gint64 *gui_size) +{ + GList *l; + gint64 memsize = 0; + + g_return_val_if_fail (func != NULL, 0); + + for (l = list; l; l = g_list_next (l)) + memsize += sizeof (GList) + func (l->data, gui_size); + + return memsize; +} + gint64 gimp_g_value_get_memsize (GValue *value) { @@ -210,6 +283,20 @@ gimp_g_param_spec_get_memsize (GParamSpec *pspec) return memsize + gimp_g_type_instance_get_memsize ((GTypeInstance *) pspec); } +gint64 +gimp_parasite_get_memsize (GimpParasite *parasite, + gint64 *gui_size) +{ + gint64 memsize = 0; + + if (parasite) + memsize += (sizeof (GimpParasite) + + strlen (parasite->name) + 1 + + parasite->size); + + return memsize; +} + /* * basically copied from gtk_get_default_language() diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h index 38f5129553..b2dfa8d8e4 100644 --- a/app/core/gimp-utils.h +++ b/app/core/gimp-utils.h @@ -20,35 +20,48 @@ #define __APP_GIMP_UTILS_H__ -gint64 gimp_g_type_instance_get_memsize (GTypeInstance *instance); -gint64 gimp_g_object_get_memsize (GObject *object); -gint64 gimp_g_hash_table_get_memsize (GHashTable *hash); -gint64 gimp_g_slist_get_memsize (GSList *slist, - gint64 data_size); -gint64 gimp_g_list_get_memsize (GList *list, - gint64 data_size); -gint64 gimp_g_value_get_memsize (GValue *value); -gint64 gimp_g_param_spec_get_memsize (GParamSpec *pspec); +gint64 gimp_g_type_instance_get_memsize (GTypeInstance *instance); +gint64 gimp_g_object_get_memsize (GObject *object); +gint64 gimp_g_hash_table_get_memsize (GHashTable *hash, + gint64 data_size); +gint64 gimp_g_hash_table_get_memsize_foreach (GHashTable *hash, + GimpMemsizeFunc func, + gint64 *gui_size); +gint64 gimp_g_slist_get_memsize (GSList *slist, + gint64 data_size); +gint64 gimp_g_slist_get_memsize_foreach (GSList *slist, + GimpMemsizeFunc func, + gint64 *gui_size); +gint64 gimp_g_list_get_memsize (GList *list, + gint64 data_size); +gint64 gimp_g_list_get_memsize_foreach (GList *slist, + GimpMemsizeFunc func, + gint64 *gui_size); +gint64 gimp_g_value_get_memsize (GValue *value); +gint64 gimp_g_param_spec_get_memsize (GParamSpec *pspec); -gchar * gimp_get_default_language (const gchar *category); -GimpUnit gimp_get_default_unit (void); +gint64 gimp_parasite_get_memsize (GimpParasite *parasite, + gint64 *gui_size); -GParameter * gimp_parameters_append (GType object_type, - GParameter *params, - gint *n_params, - ...) G_GNUC_NULL_TERMINATED; -GParameter * gimp_parameters_append_valist (GType object_type, - GParameter *params, - gint *n_params, - va_list args); -void gimp_parameters_free (GParameter *params, - gint n_params); +gchar * gimp_get_default_language (const gchar *category); +GimpUnit gimp_get_default_unit (void); -void gimp_value_array_truncate (GValueArray *args, - gint n_values); +GParameter * gimp_parameters_append (GType object_type, + GParameter *params, + gint *n_params, + ...) G_GNUC_NULL_TERMINATED; +GParameter * gimp_parameters_append_valist (GType object_type, + GParameter *params, + gint *n_params, + va_list args); +void gimp_parameters_free (GParameter *params, + gint n_params); -gchar * gimp_get_temp_filename (Gimp *gimp, - const gchar *extension); +void gimp_value_array_truncate (GValueArray *args, + gint n_values); + +gchar * gimp_get_temp_filename (Gimp *gimp, + const gchar *extension); #endif /* __APP_GIMP_UTILS_H__ */ diff --git a/app/core/gimp.c b/app/core/gimp.c index 025019a7b1..7fe0ba9bbf 100644 --- a/app/core/gimp.c +++ b/app/core/gimp.c @@ -433,8 +433,8 @@ gimp_get_memsize (GimpObject *object, memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->module_db)); memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->plug_in_manager)); - memsize += gimp_g_hash_table_get_memsize (gimp->image_table); - memsize += gimp_g_hash_table_get_memsize (gimp->item_table); + memsize += gimp_g_hash_table_get_memsize (gimp->image_table, 0); + memsize += gimp_g_hash_table_get_memsize (gimp->item_table, 0); memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->displays), gui_size); diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c index aa4e5fe07a..b25d612c93 100644 --- a/app/core/gimppalette.c +++ b/app/core/gimppalette.c @@ -29,6 +29,7 @@ #include "base/temp-buf.h" +#include "gimp-utils.h" #include "gimppalette.h" #include "gimppalette-load.h" #include "gimppalette-save.h" @@ -66,6 +67,8 @@ static gchar * gimp_palette_get_extension (GimpData *data); static GimpData * gimp_palette_duplicate (GimpData *data); static void gimp_palette_entry_free (GimpPaletteEntry *entry); +static gint64 gimp_palette_entry_get_memsize(GimpPaletteEntry *entry, + gint64 *gui_size); G_DEFINE_TYPE (GimpPalette, gimp_palette, GIMP_TYPE_DATA) @@ -124,18 +127,12 @@ gimp_palette_get_memsize (GimpObject *object, gint64 *gui_size) { GimpPalette *palette = GIMP_PALETTE (object); - GList *list; gint64 memsize = 0; - for (list = palette->colors; list; list = g_list_next (list)) - { - GimpPaletteEntry *entry = list->data; - - memsize += sizeof (GList) + sizeof (GimpPaletteEntry); - - if (entry->name) - memsize += strlen (entry->name) + 1; - } + memsize += gimp_g_list_get_memsize_foreach (palette->colors, + (GimpMemsizeFunc) + gimp_palette_entry_get_memsize, + gui_size); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size); @@ -498,3 +495,15 @@ gimp_palette_entry_free (GimpPaletteEntry *entry) g_free (entry->name); g_free (entry); } + +static gint64 +gimp_palette_entry_get_memsize (GimpPaletteEntry *entry, + gint64 *gui_size) +{ + gint64 memsize = sizeof (GimpPaletteEntry); + + if (entry->name) + memsize += strlen (entry->name) + 1; + + return memsize; +} diff --git a/app/core/gimpparasitelist.c b/app/core/gimpparasitelist.c index 413d793a4c..5072827049 100644 --- a/app/core/gimpparasitelist.c +++ b/app/core/gimpparasitelist.c @@ -149,19 +149,6 @@ gimp_parasite_list_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } -static void -gimp_parasite_list_get_memsize_foreach (gpointer key, - gpointer p, - gpointer m) -{ - GimpParasite *parasite = p; - gint64 *memsize = m; - - *memsize += (sizeof (GimpParasite) + - strlen (parasite->name) + 1 + - parasite->size); -} - static gint64 gimp_parasite_list_get_memsize (GimpObject *object, gint64 *gui_size) @@ -170,13 +157,10 @@ gimp_parasite_list_get_memsize (GimpObject *object, gint64 memsize = 0; if (list->table) - { - memsize += gimp_g_hash_table_get_memsize (list->table); - - g_hash_table_foreach (list->table, - gimp_parasite_list_get_memsize_foreach, - &memsize); - } + memsize += gimp_g_hash_table_get_memsize_foreach (list->table, + (GimpMemsizeFunc) + gimp_parasite_get_memsize, + gui_size); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size); diff --git a/app/pdb/gimppdb.c b/app/pdb/gimppdb.c index dca77a56b9..0cb04d2477 100644 --- a/app/pdb/gimppdb.c +++ b/app/pdb/gimppdb.c @@ -60,9 +60,8 @@ static void gimp_pdb_real_unregister_procedure (GimpPDB *pdb, static void gimp_pdb_entry_free (gpointer key, gpointer value, gpointer user_data); -static void gimp_pdb_entry_memsize (gpointer key, - gpointer value, - gpointer user_data); +static gint64 gimp_pdb_entry_get_memsize (GList *procedures, + gint64 *gui_size); G_DEFINE_TYPE (GimpPDB, gimp_pdb, GIMP_TYPE_OBJECT) @@ -141,10 +140,11 @@ gimp_pdb_get_memsize (GimpObject *object, GimpPDB *pdb = GIMP_PDB (object); gint64 memsize = 0; - memsize += gimp_g_hash_table_get_memsize (pdb->procedures); - memsize += gimp_g_hash_table_get_memsize (pdb->compat_proc_names); - - g_hash_table_foreach (pdb->procedures, gimp_pdb_entry_memsize, &memsize); + memsize += gimp_g_hash_table_get_memsize_foreach (pdb->procedures, + (GimpMemsizeFunc) + gimp_pdb_entry_get_memsize, + gui_size); + memsize += gimp_g_hash_table_get_memsize (pdb->compat_proc_names, 0); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size); @@ -452,17 +452,12 @@ gimp_pdb_entry_free (gpointer key, } } -static void -gimp_pdb_entry_memsize (gpointer key, - gpointer value, - gpointer user_data) +static gint64 +gimp_pdb_entry_get_memsize (GList *procedures, + gint64 *gui_size) { - if (value) - { - gint64 *memsize = user_data; - GList *list; - - for (list = value; list; list = g_list_next (list)) - *memsize += sizeof (GList) + gimp_object_get_memsize (list->data, NULL); - } + return gimp_g_list_get_memsize_foreach (procedures, + (GimpMemsizeFunc) + gimp_object_get_memsize, + gui_size); } diff --git a/app/plug-in/gimppluginmanager.c b/app/plug-in/gimppluginmanager.c index 8f77dbcc11..51bd111d77 100644 --- a/app/plug-in/gimppluginmanager.c +++ b/app/plug-in/gimppluginmanager.c @@ -209,6 +209,13 @@ gimp_plug_in_manager_finalize (GObject *object) manager->plug_in_procedures = NULL; } + if (manager->plug_in_defs) + { + g_slist_foreach (manager->plug_in_defs, (GFunc) g_object_unref, NULL); + g_slist_free (manager->plug_in_defs); + manager->plug_in_defs = NULL; + } + if (manager->shm) { gimp_plug_in_shm_free (manager->shm); @@ -248,21 +255,33 @@ gimp_plug_in_manager_get_memsize (GimpObject *object, GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object); gint64 memsize = 0; - memsize += gimp_g_slist_get_memsize (manager->load_procs, 0 /* FIXME */); - memsize += gimp_g_slist_get_memsize (manager->save_procs, 0 /* FIXME */); + memsize += gimp_g_slist_get_memsize_foreach (manager->plug_in_defs, + (GimpMemsizeFunc) + gimp_object_get_memsize, + gui_size); - memsize += gimp_g_slist_get_memsize (manager->menu_branches, - 0 /* FIXME */); - memsize += gimp_g_slist_get_memsize (manager->locale_domains, - 0 /* FIXME */); - memsize += gimp_g_slist_get_memsize (manager->help_domains, - 0 /* FIXME */); + memsize += gimp_g_slist_get_memsize (manager->plug_in_procedures, 0); + memsize += gimp_g_slist_get_memsize (manager->load_procs, 0); + memsize += gimp_g_slist_get_memsize (manager->save_procs, 0); + + memsize += gimp_g_slist_get_memsize (manager->menu_branches, 0 /* FIXME */); + memsize += gimp_g_slist_get_memsize (manager->locale_domains, 0 /* FIXME */); + memsize += gimp_g_slist_get_memsize (manager->help_domains, 0 /* FIXME */); + + memsize += gimp_g_slist_get_memsize_foreach (manager->open_plug_ins, + (GimpMemsizeFunc) + gimp_object_get_memsize, + gui_size); + memsize += gimp_g_slist_get_memsize (manager->plug_in_stack, 0 /* FIXME */); + memsize += gimp_g_slist_get_memsize (manager->history, 0); + + memsize += 0; /* FIXME manager->shm */ memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->interpreter_db), gui_size); memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->environ_table), gui_size); - memsize += gimp_g_list_get_memsize (manager->data_list, - 0 /* FIXME */); + memsize += 0; /* FIXME manager->plug_in_debug */ + memsize += gimp_g_list_get_memsize (manager->data_list, 0 /* FIXME */); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size);