[gtk] container: Don't use forall() in get_request_mode



commit 781400f6d3bda0471976917d58e2b245844f0911
Author: Timm Bäder <mail baedert org>
Date:   Sat Mar 17 14:54:23 2018 +0100

    container: Don't use forall() in get_request_mode
    
    We can just use the widget child list, which save some code.

 gtk/gtkcontainer.c | 55 ++++++++++++++++++++++++------------------------------
 1 file changed, 24 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index fabdb983f9..7ceb758868 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -1709,45 +1709,38 @@ gtk_container_real_check_resize (GtkContainer *container)
     }
 }
 
-typedef struct {
-  gint hfw;
-  gint wfh;
-} RequestModeCount;
-
-static void
-count_request_modes (GtkWidget        *widget,
-                    RequestModeCount *count)
-{
-  GtkSizeRequestMode mode = gtk_widget_get_request_mode (widget);
-
-  switch (mode)
-    {
-    case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
-      count->hfw++;
-      break;
-    case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
-      count->wfh++;
-      break;
-    case GTK_SIZE_REQUEST_CONSTANT_SIZE:
-    default:
-      break;
-    }
-}
-
 static GtkSizeRequestMode 
 gtk_container_get_request_mode (GtkWidget *widget)
 {
-  GtkContainer *container = GTK_CONTAINER (widget);
-  RequestModeCount count = { 0, 0 };
+  GtkWidget *w;
+  int wfh = 0, hfw = 0;
+
+  for (w = gtk_widget_get_first_child (widget);
+       w != NULL;
+       w = gtk_widget_get_next_sibling (w))
+    {
+      GtkSizeRequestMode mode = gtk_widget_get_request_mode (w);
 
-  gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
+      switch (mode)
+        {
+        case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
+          hfw ++;
+          break;
+        case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
+          wfh ++;
+          break;
+        case GTK_SIZE_REQUEST_CONSTANT_SIZE:
+        default:
+          break;
+        }
+    }
 
-  if (!count.hfw && !count.wfh)
+  if (hfw == 0 && wfh == 0)
     return GTK_SIZE_REQUEST_CONSTANT_SIZE;
   else
-    return count.wfh > count.hfw ? 
+    return wfh > hfw ?
         GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
-       GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+        GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
 }
 
 /**


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