[gnome-text-editor] spellcheck: try harder to avoid reloading corrections



commit ad126a07ba8e4eb1f7ad01cf3355dc6a2424c0ff
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 12 14:13:04 2021 -0800

    spellcheck: try harder to avoid reloading corrections
    
    The less we can change menuing the better from a performance perspective.
    
    Related #220

 src/editor-source-view.c |  1 +
 src/editor-spell-menu.c  | 10 +++++++++-
 src/editor-spell-menu.h  |  1 +
 3 files changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/src/editor-source-view.c b/src/editor-source-view.c
index 85612f7..974f977 100644
--- a/src/editor-source-view.c
+++ b/src/editor-source-view.c
@@ -219,6 +219,7 @@ cleanup:
   gtk_widget_action_set_enabled (GTK_WIDGET (self), "spelling.add", self->spelling_word != NULL);
   gtk_widget_action_set_enabled (GTK_WIDGET (self), "spelling.ignore", self->spelling_word != NULL);
   editor_spell_menu_set_corrections (self->spelling_menu,
+                                     self->spelling_word,
                                      (const char * const *)corrections);
 }
 
diff --git a/src/editor-spell-menu.c b/src/editor-spell-menu.c
index da4ba88..39b57c4 100644
--- a/src/editor-spell-menu.c
+++ b/src/editor-spell-menu.c
@@ -34,6 +34,7 @@ G_DECLARE_FINAL_TYPE (EditorSpellCorrections, editor_spell_corrections, EDITOR,
 struct _EditorSpellCorrections
 {
   GMenuModel parent_instance;
+  char *word;
   char **corrections;
 };
 
@@ -113,6 +114,7 @@ editor_spell_corrections_init (EditorSpellCorrections *self)
 
 static void
 editor_spell_corrections_set (EditorSpellCorrections *self,
+                              const char             *word,
                               const char * const     *corrections)
 {
   guint removed = 0;
@@ -123,12 +125,17 @@ editor_spell_corrections_set (EditorSpellCorrections *self,
   if (corrections == (const char * const *)self->corrections)
     return;
 
+  if (g_strcmp0 (word, self->word) == 0)
+    return;
+
   if (self->corrections != NULL)
     removed = g_strv_length (self->corrections);
 
   if (corrections != NULL)
     added = g_strv_length ((char **)corrections);
 
+  g_free (self->word);
+  self->word = g_strdup (word);
   g_strfreev (self->corrections);
   self->corrections = g_strdupv ((char **)corrections);
   g_menu_model_items_changed (G_MENU_MODEL (self), 0, removed, added);
@@ -200,6 +207,7 @@ editor_spell_menu_new (void)
 
 void
 editor_spell_menu_set_corrections (GMenuModel         *menu,
+                                   const char         *word,
                                    const char * const *words)
 {
   EditorSpellCorrections *corrections_menu;
@@ -209,6 +217,6 @@ editor_spell_menu_set_corrections (GMenuModel         *menu,
   if ((corrections_menu = g_object_get_data (G_OBJECT (menu), "CORRECTIONS_MENU")))
     {
       g_assert (EDITOR_IS_SPELL_CORRECTIONS (corrections_menu));
-      editor_spell_corrections_set (corrections_menu, words);
+      editor_spell_corrections_set (corrections_menu, word, words);
     }
 }
diff --git a/src/editor-spell-menu.h b/src/editor-spell-menu.h
index 26ed4f1..8a8ce17 100644
--- a/src/editor-spell-menu.h
+++ b/src/editor-spell-menu.h
@@ -28,6 +28,7 @@ GMenuModel *editor_spell_menu_new             (void);
 void        editor_spell_menu_set_language    (GMenuModel          *menu,
                                                EditorSpellLanguage *language);
 void        editor_spell_menu_set_corrections (GMenuModel          *menu,
+                                               const char          *word,
                                                const char * const  *words);
 
 G_END_DECLS


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