vcl/inc/unx/gtk/glomenu.h      |    6 ++++--
 vcl/inc/unx/gtk/gtksalmenu.hxx |    2 +-
 vcl/unx/gtk3/glomenu.cxx       |   12 ++++++++----
 vcl/unx/gtk3/gtksalmenu.cxx    |   20 ++++++++++++++------
 4 files changed, 27 insertions(+), 13 deletions(-)

New commits:
commit a18b0b4aa56c47cadd0b6d6d1ad5842cf16e9835
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Sat Aug 10 21:05:03 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Aug 11 18:18:15 2024 +0200

    speed up menu construction at app startup
    
    we spend a lot of time constructing menus, mostly because we trigger
    events for every tiny change to a menu item
    
    Change-Id: I8f81e406b577c27c9f4bcfe23bf644d751bb5d92
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171723
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/inc/unx/gtk/glomenu.h b/vcl/inc/unx/gtk/glomenu.h
index da41e9e4b8b1..427a0a8ba79c 100644
--- a/vcl/inc/unx/gtk/glomenu.h
+++ b/vcl/inc/unx/gtk/glomenu.h
@@ -76,7 +76,8 @@ void        g_lo_menu_set_icon                                
         (GLOMenu
 void        g_lo_menu_set_label_to_item_in_section                      
(GLOMenu     *menu,
                                                                          gint  
       section,
                                                                          gint  
       position,
-                                                                         const 
gchar *label);
+                                                                         const 
gchar *label,
+                                                                         bool 
fire_event = true);
 
 void        g_lo_menu_set_icon_to_item_in_section                      
(GLOMenu     *menu,
                                                                         gint   
      section,
@@ -101,7 +102,8 @@ void        
g_lo_menu_set_action_and_target_value_to_item_in_section    (GLOMenu
 void        g_lo_menu_set_command_to_item_in_section                    
(GLOMenu     *menu,
                                                                          gint  
       section,
                                                                          gint  
       position,
-                                                                         const 
gchar *command);
+                                                                         const 
gchar *command,
+                                                                         bool 
fire_event = true);
 
 gchar *     g_lo_menu_get_command_from_item_in_section                  
(GLOMenu     *menu,
                                                                          gint  
       section,
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 4157df9d3bf6..1a152a7142e1 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -94,7 +94,7 @@ public:
     void                        SetActionGroup( GActionGroup* pActionGroup ) { 
mpActionGroup = pActionGroup; }
     bool                        IsItemVisible( unsigned nPos );
 
-    void                        NativeSetItemText( unsigned nSection, unsigned 
nItemPos, const OUString& rText );
+    void                        NativeSetItemText( unsigned nSection, unsigned 
nItemPos, const OUString& rText, bool bFireEvent = true );
     void                        NativeSetItemIcon( unsigned nSection, unsigned 
nItemPos, const Image& rImage );
     bool                        NativeSetItemCommand( unsigned nSection,
                                                       unsigned nItemPos,
diff --git a/vcl/unx/gtk3/glomenu.cxx b/vcl/unx/gtk3/glomenu.cxx
index 779d20f9b879..0a535002a2d9 100644
--- a/vcl/unx/gtk3/glomenu.cxx
+++ b/vcl/unx/gtk3/glomenu.cxx
@@ -266,7 +266,8 @@ void
 g_lo_menu_set_label_to_item_in_section (GLOMenu     *menu,
                                         gint         section,
                                         gint         position,
-                                        const gchar *label)
+                                        const gchar *label,
+                                        bool fire_event)
 {
     g_return_if_fail (G_IS_LO_MENU (menu));
 
@@ -277,7 +278,8 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_label (model, position, label);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+    if (fire_event)
+        g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
 }
@@ -426,7 +428,8 @@ void
 g_lo_menu_set_command_to_item_in_section (GLOMenu     *menu,
                                           gint         section,
                                           gint         position,
-                                          const gchar *command)
+                                          const gchar *command,
+                                          bool fire_event)
 {
     g_return_if_fail (G_IS_LO_MENU (menu));
 
@@ -444,7 +447,8 @@ g_lo_menu_set_command_to_item_in_section (GLOMenu     *menu,
     g_lo_menu_set_attribute_value (model, position, 
G_LO_MENU_ATTRIBUTE_COMMAND, value);
 
     // Notify the update.
-    g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
+    if (fire_event)
+        g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
 
     g_object_unref (model);
 }
diff --git a/vcl/unx/gtk3/gtksalmenu.cxx b/vcl/unx/gtk3/gtksalmenu.cxx
index 96e362428b9d..fed134d179f9 100644
--- a/vcl/unx/gtk3/gtksalmenu.cxx
+++ b/vcl/unx/gtk3/gtksalmenu.cxx
@@ -300,18 +300,24 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool 
bRemoveDisabledEntries)
         gchar* aNativeCommand = GetCommandForItem(pSalMenuItem);
 
         // Force updating of native menu labels.
-        NativeSetItemText( nSection, nItemPos, aText );
-        NativeSetItemIcon( nSection, nItemPos, aImage );
-        NativeSetAccelerator(nSection, nItemPos, nAccelKey, 
nAccelKey.GetName());
 
         if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu 
== nullptr )
         {
+            NativeSetItemText( nSection, nItemPos, aText, false );
+            NativeSetItemIcon( nSection, nItemPos, aImage );
+            NativeSetAccelerator(nSection, nItemPos, nAccelKey, 
nAccelKey.GetName());
             NativeSetItemCommand( nSection, nItemPos, nId, aNativeCommand, 
itemBits, bChecked, false );
             NativeCheckItem( nSection, nItemPos, itemBits, bChecked );
             NativeSetEnableItem( aNativeCommand, bEnabled );
 
             pNewCommandList = g_list_append( pNewCommandList, g_strdup( 
aNativeCommand ) );
         }
+        else
+        {
+            NativeSetItemText( nSection, nItemPos, aText );
+            NativeSetItemIcon( nSection, nItemPos, aImage );
+            NativeSetAccelerator(nSection, nItemPos, nAccelKey, 
nAccelKey.GetName());
+        }
 
         GtkSalMenu* pSubmenu = pSalMenuItem->mpSubMenu;
 
@@ -1234,7 +1240,7 @@ void GtkSalMenu::NativeSetEnableItem( gchar const * 
aCommand, gboolean bEnable )
         g_lo_action_group_set_action_enabled( pActionGroup, aCommand, bEnable 
);
 }
 
-void GtkSalMenu::NativeSetItemText( unsigned nSection, unsigned nItemPos, 
const OUString& rText )
+void GtkSalMenu::NativeSetItemText( unsigned nSection, unsigned nItemPos, 
const OUString& rText, bool bFireEvent )
 {
     SolarMutexGuard aGuard;
     // Escape all underscores so that they don't get interpreted as hotkeys
@@ -1247,7 +1253,7 @@ void GtkSalMenu::NativeSetItemText( unsigned nSection, 
unsigned nItemPos, const
     gchar* aLabel = g_lo_menu_get_label_from_item_in_section( G_LO_MENU( 
mpMenuModel ), nSection, nItemPos );
 
     if ( aLabel == nullptr || g_strcmp0( aLabel, aConvertedText.getStr() ) != 
0 )
-        g_lo_menu_set_label_to_item_in_section( G_LO_MENU( mpMenuModel ), 
nSection, nItemPos, aConvertedText.getStr() );
+        g_lo_menu_set_label_to_item_in_section( G_LO_MENU( mpMenuModel ), 
nSection, nItemPos, aConvertedText.getStr(), bFireEvent );
 
     if ( aLabel )
         g_free( aLabel );
@@ -1377,7 +1383,9 @@ bool GtkSalMenu::NativeSetItemCommand( unsigned nSection,
             g_free(pLabel);
         }
 
-        g_lo_menu_set_command_to_item_in_section( pMenu, nSection, nItemPos, 
aCommand );
+        // suppress event firing here, we will do so anyway in the 
g_lo_menu_set_action_and_target_value_to_item_in_section call,
+        // speeds up constructing menus
+        g_lo_menu_set_command_to_item_in_section( pMenu, nSection, nItemPos, 
aCommand, /*fire_event*/false );
 
         gchar* aItemCommand = g_strconcat("win.", aCommand, nullptr );
 

Reply via email to