[gimp] app: Use GimpIdTable
- From: Martin Nordholts <martinn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: Use GimpIdTable
- Date: Wed, 4 May 2011 20:53:39 +0000 (UTC)
commit 0d529f79566a2a81aeb94fb833ad9a69946dd36c
Author: Martin Nordholts <martinn src gnome org>
Date: Wed May 4 22:14:13 2011 +0200
app: Use GimpIdTable
app/core/gimp.c | 15 +++++++--------
app/core/gimp.h | 6 ++----
app/core/gimpimage.c | 21 ++++-----------------
app/core/gimpitem.c | 31 +++++++++----------------------
4 files changed, 22 insertions(+), 51 deletions(-)
---
diff --git a/app/core/gimp.c b/app/core/gimp.c
index 434d1a7..f82af60 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -62,6 +62,7 @@
#include "gimpdocumentlist.h"
#include "gimpgradient-load.h"
#include "gimpgradient.h"
+#include "gimpidtable.h"
#include "gimpimage.h"
#include "gimpimagefile.h"
#include "gimplist.h"
@@ -218,13 +219,11 @@ gimp_init (Gimp *gimp)
gimp->images = gimp_list_new_weak (GIMP_TYPE_IMAGE, FALSE);
gimp_object_set_static_name (GIMP_OBJECT (gimp->images), "images");
- gimp->next_image_ID = 1;
gimp->next_guide_ID = 1;
gimp->next_sample_point_ID = 1;
- gimp->image_table = g_hash_table_new (g_direct_hash, NULL);
+ gimp->image_table = gimp_id_table_new ();
- gimp->next_item_ID = 1;
- gimp->item_table = g_hash_table_new (g_direct_hash, NULL);
+ gimp->item_table = gimp_id_table_new ();
gimp->displays = g_object_new (GIMP_TYPE_LIST,
"children-type", GIMP_TYPE_OBJECT,
@@ -417,13 +416,13 @@ gimp_finalize (GObject *object)
if (gimp->item_table)
{
- g_hash_table_destroy (gimp->item_table);
+ g_object_unref (gimp->item_table);
gimp->item_table = NULL;
}
if (gimp->image_table)
{
- g_hash_table_destroy (gimp->image_table);
+ g_object_unref (gimp->image_table);
gimp->image_table = NULL;
}
@@ -492,8 +491,8 @@ gimp_get_memsize (GimpObject *object,
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->plug_in_manager),
gui_size);
- 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->image_table), 0);
+ memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->item_table), 0);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->displays), gui_size);
diff --git a/app/core/gimp.h b/app/core/gimp.h
index 6658c19..86c160c 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -74,13 +74,11 @@ struct _Gimp
GimpPlugInManager *plug_in_manager;
GimpContainer *images;
- gint next_image_ID;
guint32 next_guide_ID;
guint32 next_sample_point_ID;
- GHashTable *image_table;
+ GimpIdTable *image_table;
- gint next_item_ID;
- GHashTable *item_table;
+ GimpIdTable *item_table;
GimpContainer *displays;
gint next_display_ID;
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 01d02cd..8661e8c 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -42,6 +42,7 @@
#include "gimpgrid.h"
#include "gimperror.h"
#include "gimpguide.h"
+#include "gimpidtable.h"
#include "gimpimage.h"
#include "gimpimage-colorhash.h"
#include "gimpimage-colormap.h"
@@ -749,19 +750,7 @@ gimp_image_constructed (GObject *object)
config = image->gimp->config;
- do
- {
- private->ID = image->gimp->next_image_ID++;
-
- if (image->gimp->next_image_ID == G_MAXINT)
- image->gimp->next_image_ID = 1;
- }
- while (g_hash_table_lookup (image->gimp->image_table,
- GINT_TO_POINTER (private->ID)));
-
- g_hash_table_insert (image->gimp->image_table,
- GINT_TO_POINTER (private->ID),
- image);
+ private->ID = gimp_id_table_insert (image->gimp->image_table, image);
template = config->default_image;
@@ -997,8 +986,7 @@ gimp_image_finalize (GObject *object)
if (image->gimp && image->gimp->image_table)
{
- g_hash_table_remove (image->gimp->image_table,
- GINT_TO_POINTER (private->ID));
+ gimp_id_table_remove (image->gimp->image_table, private->ID);
image->gimp = NULL;
}
@@ -1502,8 +1490,7 @@ gimp_image_get_by_ID (Gimp *gimp,
if (gimp->image_table == NULL)
return NULL;
- return (GimpImage *) g_hash_table_lookup (gimp->image_table,
- GINT_TO_POINTER (image_id));
+ return (GimpImage *) gimp_id_table_lookup (gimp->image_table, image_id);
}
void
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 856e962..92e5dbe 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -30,6 +30,7 @@
#include "gimp.h"
#include "gimp-parasites.h"
#include "gimpchannel.h"
+#include "gimpidtable.h"
#include "gimpimage.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
@@ -337,8 +338,7 @@ gimp_item_finalize (GObject *object)
if (private->image && private->image->gimp)
{
- g_hash_table_remove (private->image->gimp->item_table,
- GINT_TO_POINTER (private->ID));
+ gimp_id_table_remove (private->image->gimp->item_table, private->ID);
private->image = NULL;
}
@@ -1600,8 +1600,7 @@ gimp_item_get_by_ID (Gimp *gimp,
if (gimp->item_table == NULL)
return NULL;
- return (GimpItem *) g_hash_table_lookup (gimp->item_table,
- GINT_TO_POINTER (item_id));
+ return (GimpItem *) gimp_id_table_lookup (gimp->item_table, item_id);
}
GimpTattoo
@@ -1649,19 +1648,7 @@ gimp_item_set_image (GimpItem *item,
if (private->ID == 0)
{
- do
- {
- private->ID = image->gimp->next_item_ID++;
-
- if (image->gimp->next_item_ID == G_MAXINT)
- image->gimp->next_item_ID = 1;
- }
- while (g_hash_table_lookup (image->gimp->item_table,
- GINT_TO_POINTER (private->ID)));
-
- g_hash_table_insert (image->gimp->item_table,
- GINT_TO_POINTER (private->ID),
- item);
+ private->ID = gimp_id_table_insert (image->gimp->item_table, item);
g_object_notify (G_OBJECT (item), "id");
}
@@ -1715,13 +1702,13 @@ gimp_item_replace_item (GimpItem *item,
gimp_object_set_name (GIMP_OBJECT (item), gimp_object_get_name (replace));
if (private->ID)
- g_hash_table_remove (gimp_item_get_image (item)->gimp->item_table,
- GINT_TO_POINTER (gimp_item_get_ID (item)));
+ gimp_id_table_remove (gimp_item_get_image (item)->gimp->item_table,
+ gimp_item_get_ID (item));
private->ID = gimp_item_get_ID (replace);
- g_hash_table_replace (gimp_item_get_image (item)->gimp->item_table,
- GINT_TO_POINTER (gimp_item_get_ID (item)),
- item);
+ gimp_id_table_replace (gimp_item_get_image (item)->gimp->item_table,
+ gimp_item_get_ID (item),
+ item);
/* Set image before tatoo so that the explicitly set tatoo overrides
* the one implicitly set when setting the image
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]