[gnome-text-editor] spellcheck: short-circuit on numbers



commit 53bedbd4cd401d441bbeead3b926b021fe6a36ed
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 1 16:11:26 2021 -0700

    spellcheck: short-circuit on numbers
    
    We don't need to query the backend for numbers, and not all backends even have
    them (notably enchant-2 on macOS).

 src/editor-spell-checker.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/src/editor-spell-checker.c b/src/editor-spell-checker.c
index cd9c07b..1d620aa 100644
--- a/src/editor-spell-checker.c
+++ b/src/editor-spell-checker.c
@@ -20,6 +20,8 @@
 
 #include "config.h"
 
+#include <string.h>
+
 #include "editor-spell-checker.h"
 #include "editor-spell-language.h"
 #include "editor-spell-provider.h"
@@ -238,6 +240,21 @@ editor_spell_checker_get_provider (EditorSpellChecker *self)
   return self->provider;
 }
 
+static inline gboolean
+word_is_number (const char *word,
+                gssize      word_len)
+{
+  g_assert (word_len > 0);
+
+  for (gssize i = 0; i < word_len; i++)
+    {
+      if (word[i] < '0' || word[i] > '9')
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 gboolean
 editor_spell_checker_check_word (EditorSpellChecker *self,
                                  const char         *word,
@@ -251,5 +268,11 @@ editor_spell_checker_check_word (EditorSpellChecker *self,
   if (self->language == NULL)
     return TRUE;
 
+  if (word_len < 0)
+    word_len = strlen (word);
+
+  if (word_is_number (word, word_len))
+    return TRUE;
+
   return editor_spell_language_contains_word (self->language, word, word_len);
 }


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