[gtk+] sizerequest: Cache the request mode
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] sizerequest: Cache the request mode
- Date: Wed, 14 Nov 2012 01:05:13 +0000 (UTC)
commit c08efb2b3291692dd3ad12cc95d4daf3735a0630
Author: Benjamin Otte <otte redhat com>
Date: Tue Nov 13 22:02:53 2012 +0100
sizerequest: Cache the request mode
... in the GtkSizeRequestCache. That way, we only need to query it once,
and can remove the caching code from GtkContainer.
gtk/gtkcontainer.c | 30 +++++++++++-------------------
gtk/gtksizegroup.c | 2 ++
gtk/gtksizerequest.c | 32 ++++++++++++--------------------
gtk/gtksizerequestcacheprivate.h | 3 +++
4 files changed, 28 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 52eeae8..6f50359 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -42,6 +42,7 @@
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtksizerequest.h"
+#include "gtksizerequestcacheprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
#include "gtkassistant.h"
@@ -1755,6 +1756,7 @@ _gtk_container_queue_resize_internal (GtkContainer *container,
_gtk_widget_set_alloc_needed (widget, TRUE);
_gtk_widget_set_width_request_needed (widget, TRUE);
_gtk_widget_set_height_request_needed (widget, TRUE);
+ _gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget));
if (GTK_IS_RESIZE_CONTAINER (widget))
break;
@@ -1968,27 +1970,17 @@ count_request_modes (GtkWidget *widget,
static GtkSizeRequestMode
gtk_container_get_request_mode (GtkWidget *widget)
{
- GtkContainer *container = GTK_CONTAINER (widget);
- GtkContainerPrivate *priv = container->priv;
-
- /* Recalculate the request mode of the children by majority
- * vote whenever the internal content changes */
- if (_gtk_widget_get_width_request_needed (widget) ||
- _gtk_widget_get_height_request_needed (widget))
- {
- RequestModeCount count = { 0, 0 };
+ GtkContainer *container = GTK_CONTAINER (widget);
+ RequestModeCount count = { 0, 0 };
- gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
+ gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
- if (!count.hfw && !count.wfh)
- priv->request_mode = GTK_SIZE_REQUEST_CONSTANT_SIZE;
- else
- priv->request_mode = count.wfh > count.hfw ?
- GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
- GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
- }
-
- return priv->request_mode;
+ if (!count.hfw && !count.wfh)
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+ else
+ return count.wfh > count.hfw ?
+ GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
+ GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
/**
diff --git a/gtk/gtksizegroup.c b/gtk/gtksizegroup.c
index 39e4b92..bcd9255 100644
--- a/gtk/gtksizegroup.c
+++ b/gtk/gtksizegroup.c
@@ -25,6 +25,7 @@
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include "gtksizegroup-private.h"
+#include "gtksizerequestcacheprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkcontainerprivate.h"
@@ -198,6 +199,7 @@ real_queue_resize (GtkWidget *widget,
_gtk_widget_set_alloc_needed (widget, TRUE);
_gtk_widget_set_width_request_needed (widget, TRUE);
_gtk_widget_set_height_request_needed (widget, TRUE);
+ _gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget));
container = gtk_widget_get_parent (widget);
if (!container &&
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index eff854f..99191f5 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -84,24 +84,6 @@ pop_recursion_check (GtkWidget *widget,
}
-/* 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)
-{
- SizeRequestCache *cache;
-
- cache = _gtk_widget_peek_request_cache (widget);
-
- if (_gtk_widget_get_width_request_needed (widget) ||
- _gtk_widget_get_height_request_needed (widget))
- _gtk_size_request_cache_clear (cache);
-
- return cache;
-}
-
/* looks for a cached size request for this for_size. If not
* found, returns the oldest entry so it can be overwritten
*
@@ -118,7 +100,7 @@ get_cached_size (GtkWidget *widget,
SizeRequest **cached_sizes;
guint i, n_sizes;
- cache = init_cache (widget);
+ cache = _gtk_widget_peek_request_cache (widget);
if (for_size < 0)
{
@@ -507,9 +489,19 @@ _gtk_widget_compute_size_for_orientation (GtkWidget *widget,
GtkSizeRequestMode
gtk_widget_get_request_mode (GtkWidget *widget)
{
+ SizeRequestCache *cache;
+
g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_SIZE_REQUEST_CONSTANT_SIZE);
- return GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
+ cache = _gtk_widget_peek_request_cache (widget);
+
+ if (!cache->request_mode_valid)
+ {
+ cache->request_mode = GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
+ cache->request_mode_valid = TRUE;
+ }
+
+ return cache->request_mode;
}
/**
diff --git a/gtk/gtksizerequestcacheprivate.h b/gtk/gtksizerequestcacheprivate.h
index 60c061b..db15aa5 100644
--- a/gtk/gtksizerequestcacheprivate.h
+++ b/gtk/gtksizerequestcacheprivate.h
@@ -26,6 +26,7 @@
#define __GTK_SIZE_REQUEST_CACHE_PRIVATE_H__
#include <glib.h>
+#include <gtk/gtkenums.h>
G_BEGIN_DECLS
@@ -56,6 +57,8 @@ typedef struct {
CachedSize cached_width;
CachedSize cached_height;
+ GtkSizeRequestMode request_mode: 3;
+ guint request_mode_valid : 1;
guint cached_widths : 3;
guint cached_heights : 3;
guint last_cached_width : 3;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]