From f274dce25b4eb95d37a9f82563564e7a3579aa11 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 13 Jul 2004 10:09:22 +0000 Subject: [PATCH] added new function gimp_g_value_get_memsize() that attempts to calculate 2004-07-13 Sven Neumann * app/core/gimp-utils.[ch]: added new function gimp_g_value_get_memsize() that attempts to calculate the memory requirements for a GValue. * app/text/gimptextundo.c (gimp_text_undo_get_memsize): use the new function to obtain a better estimate for the size of the text undo. --- ChangeLog | 10 ++++++++++ app/core/gimp-utils.c | 35 +++++++++++++++++++++++++++++++++++ app/core/gimp-utils.h | 1 + app/text/gimptextundo.c | 15 ++++++--------- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d125d2a09..350bbb5035 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-07-13 Sven Neumann + + * app/core/gimp-utils.[ch]: added new function + gimp_g_value_get_memsize() that attempts to calculate the memory + requirements for a GValue. + + * app/text/gimptextundo.c (gimp_text_undo_get_memsize): use the + new function to obtain a better estimate for the size of the text + undo. + 2004-07-13 Sven Neumann * app/tools/gimptexttool.c (gimp_text_tool_create_layer): plugged diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c index 3c5e4614ab..b9cba4cad5 100644 --- a/app/core/gimp-utils.c +++ b/app/core/gimp-utils.c @@ -27,6 +27,8 @@ #include "core-types.h" +#include "config/gimpconfig-types.h" + #include "gimp-utils.h" @@ -99,6 +101,39 @@ gimp_g_list_get_memsize (GList *list, return g_list_length (list) * (data_size + sizeof (GList)); } +gint64 +gimp_g_value_get_memsize (GValue *value) +{ + gint64 memsize = sizeof (GValue); + + if (G_VALUE_HOLDS_STRING (value)) + { + memsize += strlen (g_value_get_string (value)) + 1; + } + else if (G_VALUE_HOLDS_BOXED (value)) + { + if (GIMP_VALUE_HOLDS_COLOR (value)) + { + memsize += sizeof (GimpRGB); + } + else if (GIMP_VALUE_HOLDS_MATRIX2 (value)) + { + memsize += sizeof (GimpMatrix2); + } + else + { + g_warning ("%s: unhandled boxed value type: %s", + G_STRFUNC, G_VALUE_TYPE_NAME (value)); + } + } + else if (G_VALUE_HOLDS_OBJECT (value)) + { + g_warning ("%s: unhandled object value type: %s", + G_STRFUNC, G_VALUE_TYPE_NAME (value)); + } + + return memsize; +} /* * basically copied from gtk_get_default_language() diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h index 5023907c06..1cebdc8c1d 100644 --- a/app/core/gimp-utils.h +++ b/app/core/gimp-utils.h @@ -39,6 +39,7 @@ 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); gchar * gimp_get_default_language (const gchar *category); diff --git a/app/text/gimptextundo.c b/app/text/gimptextundo.c index ec14878a27..9e70727cf8 100644 --- a/app/text/gimptextundo.c +++ b/app/text/gimptextundo.c @@ -27,6 +27,7 @@ #include "core/gimpitem.h" #include "core/gimpitemundo.h" +#include "core/gimp-utils.h" #include "gimptext.h" #include "gimptextlayer.h" @@ -199,15 +200,11 @@ gimp_text_undo_get_memsize (GimpObject *object, GimpTextUndo *undo = GIMP_TEXT_UNDO (object); gint64 memsize = 0; - if (undo->pspec) - { - /* this is incorrect, but how can it be done better? */ - memsize = sizeof (GValue); - } - else if (undo->text) - { - memsize = gimp_object_get_memsize (GIMP_OBJECT (undo->text), NULL); - } + if (undo->value) + memsize += gimp_g_value_get_memsize (undo->value); + + if (undo->text) + memsize += gimp_object_get_memsize (GIMP_OBJECT (undo->text), NULL); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size);