[gtk+/gtk-3-0] Revert "Reduce memory consumption of the size request cache."
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-0] Revert "Reduce memory consumption of the size request cache."
- Date: Sat, 2 Apr 2011 18:11:41 +0000 (UTC)
commit c69d473a3b8cb3d2885d6e529bf6ee3f533515ef
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Apr 2 11:13:07 2011 -0400
Revert "Reduce memory consumption of the size request cache."
This reverts commit 148d4cd3fa6eaae027baad89c9c479dfb1a9122c.
gtk/gtksizerequest.c | 168 +++++++++++++++--------------------------------
gtk/gtkwidget.c | 3 -
gtk/gtkwidgetprivate.h | 20 ++----
3 files changed, 59 insertions(+), 132 deletions(-)
---
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index e299c40..8526d59 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -34,114 +34,27 @@
/* looks for a cached size request for this for_size. If not
* found, returns the oldest entry so it can be overwritten
*
- * Note that this caching code was originally derived from
+ * Note that this caching code was directly derived from
* the Clutter toolkit.
*/
-
-
-/* This function checks if 'request_needed' flag is present
- * and resets the cache state if a request is needed for
- * a given orientation.
- */
-static SizeRequestCache *
-init_cache (GtkWidget *widget,
- GtkSizeGroupMode orientation)
-{
- GtkSizeRequestMode mode;
- SizeRequestCache *cache;
-
- cache = _gtk_widget_peek_request_cache (widget);
-
- if (orientation == GTK_SIZE_GROUP_HORIZONTAL &&
- _gtk_widget_get_width_request_needed (widget))
- {
- mode = gtk_widget_get_request_mode (widget);
-
- if (mode == GTK_SIZE_REQUEST_CONSTANT_SIZE)
- {
- if (cache->sizes)
- {
- g_slice_free (ContextualSizes, cache->sizes);
- cache->sizes = NULL;
- }
- }
- else
- {
- if (!cache->sizes)
- cache->sizes = g_slice_new0 (ContextualSizes);
-
- memset (cache->sizes->widths, 0x0, GTK_SIZE_REQUEST_CACHED_SIZES * sizeof (SizeRequest));
- cache->sizes->cached_widths = 0;
- cache->sizes->last_cached_width = 0;
- }
-
- cache->cached_width.minimum_size = -1;
- cache->cached_width.natural_size = -1;
- }
- else if (orientation == GTK_SIZE_GROUP_VERTICAL &&
- _gtk_widget_get_height_request_needed (widget))
- {
- mode = gtk_widget_get_request_mode (widget);
-
- if (mode == GTK_SIZE_REQUEST_CONSTANT_SIZE)
- {
- if (cache->sizes)
- {
- g_slice_free (ContextualSizes, cache->sizes);
- cache->sizes = NULL;
- }
- }
- else
- {
- if (!cache->sizes)
- cache->sizes = g_slice_new0 (ContextualSizes);
-
- memset (cache->sizes->heights, 0x0, GTK_SIZE_REQUEST_CACHED_SIZES * sizeof (SizeRequest));
- cache->sizes->cached_heights = 0;
- cache->sizes->last_cached_height = 0;
- }
-
- cache->cached_height.minimum_size = -1;
- cache->cached_height.natural_size = -1;
- }
-
- return cache;
-}
-
static gboolean
-get_cached_size (GtkWidget *widget,
+get_cached_size (SizeRequestCache *cache,
GtkSizeGroupMode orientation,
gint for_size,
- CachedSize **result)
+ SizeRequest **result)
{
- SizeRequestCache *cache;
- SizeRequest *cached_sizes;
- guint i, n_sizes;
-
- cache = init_cache (widget, orientation);
-
- if (for_size < 0)
- {
- if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
- *result = &cache->cached_width;
- else
- *result = &cache->cached_height;
-
- if ((*result)->minimum_size < 0)
- return FALSE;
- else
- return TRUE;
- }
+ guint i, n_sizes;
+ SizeRequest *cached_sizes;
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
{
- cached_sizes = cache->sizes->widths;
- n_sizes = cache->sizes->cached_widths;
+ cached_sizes = cache->widths;
+ n_sizes = cache->cached_widths;
}
else
{
- cached_sizes = cache->sizes->heights;
- n_sizes = cache->sizes->cached_widths;
+ cached_sizes = cache->heights;
+ n_sizes = cache->cached_widths;
}
/* Search for an already cached size */
@@ -149,7 +62,7 @@ get_cached_size (GtkWidget *widget,
{
if (cached_sizes[i].for_size == for_size)
{
- *result = &cached_sizes[i].cached_size;
+ *result = &cached_sizes[i];
return TRUE;
}
}
@@ -159,35 +72,33 @@ get_cached_size (GtkWidget *widget,
* and increment the last_cached_width/height right away */
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
{
- if (cache->sizes->cached_widths < GTK_SIZE_REQUEST_CACHED_SIZES)
+ if (cache->cached_widths < GTK_SIZE_REQUEST_CACHED_SIZES)
{
- cache->sizes->cached_widths++;
- cache->sizes->last_cached_width = cache->sizes->cached_widths - 1;
+ cache->cached_widths++;
+ cache->last_cached_width = cache->cached_widths - 1;
}
else
{
- if (++cache->sizes->last_cached_width == GTK_SIZE_REQUEST_CACHED_SIZES)
- cache->sizes->last_cached_width = 0;
+ if (++cache->last_cached_width == GTK_SIZE_REQUEST_CACHED_SIZES)
+ cache->last_cached_width = 0;
}
- cache->sizes->widths[cache->sizes->last_cached_width].for_size = for_size;
- *result = &cache->sizes->widths[cache->sizes->last_cached_width].cached_size;
+ *result = &cache->widths[cache->last_cached_width];
}
else /* GTK_SIZE_GROUP_VERTICAL */
{
- if (cache->sizes->cached_heights < GTK_SIZE_REQUEST_CACHED_SIZES)
+ if (cache->cached_heights < GTK_SIZE_REQUEST_CACHED_SIZES)
{
- cache->sizes->cached_heights++;
- cache->sizes->last_cached_height = cache->sizes->cached_heights - 1;
+ cache->cached_heights++;
+ cache->last_cached_height = cache->cached_heights - 1;
}
else
{
- if (++cache->sizes->last_cached_height == GTK_SIZE_REQUEST_CACHED_SIZES)
- cache->sizes->last_cached_height = 0;
+ if (++cache->last_cached_height == GTK_SIZE_REQUEST_CACHED_SIZES)
+ cache->last_cached_height = 0;
}
- cache->sizes->heights[cache->sizes->last_cached_height].for_size = for_size;
- *result = &cache->sizes->heights[cache->sizes->last_cached_height].cached_size;
+ *result = &cache->heights[cache->last_cached_height];
}
return FALSE;
@@ -257,11 +168,39 @@ compute_size_for_orientation (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
- CachedSize *cached_size;
+ SizeRequestCache *cache;
+ SizeRequest *cached_size;
gboolean found_in_cache = FALSE;
- gint adjusted_min, adjusted_natural;
+ int adjusted_min, adjusted_natural;
+
+ cache = _gtk_widget_peek_request_cache (widget);
- found_in_cache = get_cached_size (widget, orientation, for_size, &cached_size);
+ if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
+ {
+ cached_size = &cache->widths[0];
+
+ if (!_gtk_widget_get_width_request_needed (widget))
+ found_in_cache = get_cached_size (cache, orientation, for_size, &cached_size);
+ else
+ {
+ memset (cache->widths, 0, GTK_SIZE_REQUEST_CACHED_SIZES * sizeof (SizeRequest));
+ cache->cached_widths = 1;
+ cache->last_cached_width = 0;
+ }
+ }
+ else
+ {
+ cached_size = &cache->heights[0];
+
+ if (!_gtk_widget_get_height_request_needed (widget))
+ found_in_cache = get_cached_size (cache, orientation, for_size, &cached_size);
+ else
+ {
+ memset (cache->heights, 0, GTK_SIZE_REQUEST_CACHED_SIZES * sizeof (SizeRequest));
+ cache->cached_heights = 1;
+ cache->last_cached_height = 0;
+ }
+ }
if (!found_in_cache)
{
@@ -345,6 +284,7 @@ compute_size_for_orientation (GtkWidget *widget,
cached_size->minimum_size = min_size;
cached_size->natural_size = nat_size;
+ cached_size->for_size = for_size;
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
_gtk_widget_set_width_request_needed (widget, FALSE);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b72b80b..8f361b2 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -10647,9 +10647,6 @@ gtk_widget_finalize (GObject *object)
if (priv->context)
g_object_unref (priv->context);
- if (priv->requests.sizes)
- g_slice_free (ContextualSizes, priv->requests.sizes);
-
if (g_object_is_floating (object))
g_warning ("A floating object was finalized. This means that someone\n"
"called g_object_unref() on an object that had only a floating\n"
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 9dfec65..1e91290 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -34,18 +34,15 @@ G_BEGIN_DECLS
* (Note this define is limited by the bitfield sizes
* defined on the SizeRequestCache structure).
*/
-#define GTK_SIZE_REQUEST_CACHED_SIZES (2)
-
-typedef struct {
- gint minimum_size;
- gint natural_size;
-} CachedSize;
+#define GTK_SIZE_REQUEST_CACHED_SIZES (3)
typedef struct
{
/* the size this request is for */
- gint for_size;
- CachedSize cached_size;
+ gint for_size;
+
+ gint minimum_size;
+ gint natural_size;
} SizeRequest;
typedef struct {
@@ -56,13 +53,6 @@ typedef struct {
guint cached_heights : 2;
guint last_cached_width : 2;
guint last_cached_height : 2;
-} ContextualSizes;
-
-typedef struct {
- ContextualSizes *sizes;
-
- CachedSize cached_width;
- CachedSize cached_height;
} SizeRequestCache;
void _gtk_widget_set_visible_flag (GtkWidget *widget,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]