[gtk] sizerequest: Directly query new request_mode



commit f8df527c6877ca45b24ca9e0e7301f6a119209bf
Author: Timm Bäder <mail baedert org>
Date:   Sun Dec 2 09:54:25 2018 +0100

    sizerequest: Directly query new request_mode
    
    We are already inside the function that populates the size request
    cache, so do it here instead of implicitly in get_request_mode.

 gtk/gtksizerequest.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index 78f369e589..197d2413ea 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -139,10 +139,19 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
 
   gtk_widget_ensure_resize (widget);
 
-  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
+  /* We check the request mode first, to determine whether the widget even does
+   * any wfh/hfw handling. If it doesn't, we reset for_size to -1 and ensure
+   * that we only cache one size for the widget (i.e. a lot more cache hits). */
+  cache = _gtk_widget_peek_request_cache (widget);
+  if (G_UNLIKELY (!cache->request_mode_valid))
+    {
+      cache->request_mode = GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
+      cache->request_mode_valid = TRUE;
+    }
+
+  if (cache->request_mode == GTK_SIZE_REQUEST_CONSTANT_SIZE)
     for_size = -1;
 
-  cache = _gtk_widget_peek_request_cache (widget);
   found_in_cache = _gtk_size_request_cache_lookup (cache,
                                                    orientation,
                                                    for_size,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]