[gnome-text-editor] openpopover: avoid calling gtk_stack_set_visible_child()



commit 6c797d503ed80ce75804ddf6e0edf828c8d8462e
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 19:39:30 2021 -0700

    openpopover: avoid calling gtk_stack_set_visible_child()
    
    It is faster to compare against gtk_stack_get_visible_child() than to call
    gtk_stack_set_visible_child() as it looks up the page by widget.
    
    Related #192

 src/editor-open-popover.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/editor-open-popover.c b/src/editor-open-popover.c
index 070fb96..d79253e 100644
--- a/src/editor-open-popover.c
+++ b/src/editor-open-popover.c
@@ -316,13 +316,18 @@ editor_open_popover_items_changed_cb (EditorOpenPopover *self,
                                       guint              added,
                                       GListModel        *model)
 {
+  GtkWidget *child;
+
   g_assert (EDITOR_IS_OPEN_POPOVER (self));
   g_assert (G_IS_LIST_MODEL (model));
 
   if (added || g_list_model_get_n_items (model))
-    gtk_stack_set_visible_child (self->stack, self->recent);
+    child = self->recent;
   else
-    gtk_stack_set_visible_child (self->stack, self->empty);
+    child = self->empty;
+
+  if (child != gtk_stack_get_visible_child (self->stack))
+    gtk_stack_set_visible_child (self->stack, child);
 }
 
 void


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