[gspell/wip/improve-perfs: 1/5] Utils: move function to improve word boundaries on PangoLogAttrs



commit fcce4d9b154a18f9178a709f6aac5722f0e78970
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Apr 2 12:50:57 2017 +0200

    Utils: move function to improve word boundaries on PangoLogAttrs
    
    It'll be used for the GtkTextView implementation as well.

 gspell/gspell-entry-utils.c |   54 +------------------------------------------
 gspell/gspell-utils.c       |   52 +++++++++++++++++++++++++++++++++++++++++
 gspell/gspell-utils.h       |    5 ++++
 3 files changed, 58 insertions(+), 53 deletions(-)
---
diff --git a/gspell/gspell-entry-utils.c b/gspell/gspell-entry-utils.c
index 8e2dd10..4d767a0 100644
--- a/gspell/gspell-entry-utils.c
+++ b/gspell/gspell-entry-utils.c
@@ -39,58 +39,6 @@ _gspell_entry_word_free (gpointer data)
        }
 }
 
-static void
-improve_word_boundaries (const gchar  *text,
-                        PangoLogAttr *log_attrs,
-                        gint          n_attrs)
-{
-       const gchar *cur_text_pos;
-       gint attr_num;
-
-       attr_num = 0;
-       cur_text_pos = text;
-
-       while (attr_num < n_attrs)
-       {
-               PangoLogAttr *log_attr_before;
-               gunichar ch;
-               PangoLogAttr *log_attr_after;
-
-               if (cur_text_pos == NULL ||
-                   *cur_text_pos == '\0')
-               {
-                       if (attr_num != n_attrs - 1)
-                       {
-                               g_warning ("%s(): problem in loop iteration, attr_num=%d but should be %d.",
-                                          G_STRFUNC,
-                                          attr_num,
-                                          n_attrs - 1);
-                       }
-
-                       break;
-               }
-
-               g_assert_cmpint (attr_num + 1, <, n_attrs);
-
-               /* ch is between log_attr_before and log_attr_after. */
-               log_attr_before = log_attrs + attr_num;
-               ch = g_utf8_get_char (cur_text_pos);
-               log_attr_after = log_attr_before + 1;
-
-               /* Same algo as in gspell-text-iter.c. */
-               if (_gspell_utils_is_apostrophe_or_dash (ch) &&
-                   log_attr_before->is_word_end &&
-                   log_attr_after->is_word_start)
-               {
-                       log_attr_before->is_word_end = FALSE;
-                       log_attr_after->is_word_start = FALSE;
-               }
-
-               attr_num++;
-               cur_text_pos = g_utf8_find_next_char (cur_text_pos, NULL);
-       }
-}
-
 /* Without the preedit string.
  * Free @log_attrs with g_free().
  */
@@ -118,7 +66,7 @@ get_pango_log_attrs (GtkEntry      *entry,
                             *log_attrs,
                             *n_attrs);
 
-       improve_word_boundaries (text, *log_attrs, *n_attrs);
+       _gspell_utils_improve_word_boundaries (text, *log_attrs, *n_attrs);
 }
 
 /* Returns: (transfer full) (element-type GspellEntryWord): the list of words in
diff --git a/gspell/gspell-utils.c b/gspell/gspell-utils.c
index d5174d5..149a20f 100644
--- a/gspell/gspell-utils.c
+++ b/gspell/gspell-utils.c
@@ -225,4 +225,56 @@ _gspell_utils_create_pango_attr_underline_color (void)
        return pango_attr_underline_color_new (65535 * UNDERLINE_COLOR_RED_INTENSITY, 0, 0);
 }
 
+void
+_gspell_utils_improve_word_boundaries (const gchar  *text,
+                                      PangoLogAttr *log_attrs,
+                                      gint          n_attrs)
+{
+       const gchar *cur_text_pos;
+       gint attr_num;
+
+       attr_num = 0;
+       cur_text_pos = text;
+
+       while (attr_num < n_attrs)
+       {
+               PangoLogAttr *log_attr_before;
+               gunichar ch;
+               PangoLogAttr *log_attr_after;
+
+               if (cur_text_pos == NULL ||
+                   *cur_text_pos == '\0')
+               {
+                       if (attr_num != n_attrs - 1)
+                       {
+                               g_warning ("%s(): problem in loop iteration, attr_num=%d but should be %d.",
+                                          G_STRFUNC,
+                                          attr_num,
+                                          n_attrs - 1);
+                       }
+
+                       break;
+               }
+
+               g_assert_cmpint (attr_num + 1, <, n_attrs);
+
+               /* ch is between log_attr_before and log_attr_after. */
+               log_attr_before = log_attrs + attr_num;
+               ch = g_utf8_get_char (cur_text_pos);
+               log_attr_after = log_attr_before + 1;
+
+               /* Same algo as in gspell-text-iter.c. */
+               if (_gspell_utils_is_apostrophe_or_dash (ch) &&
+                   log_attr_before->is_word_end &&
+                   log_attr_after->is_word_start)
+               {
+                       log_attr_before->is_word_end = FALSE;
+                       log_attr_after->is_word_start = FALSE;
+               }
+
+               attr_num++;
+               cur_text_pos = g_utf8_find_next_char (cur_text_pos, NULL);
+       }
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gspell/gspell-utils.h b/gspell/gspell-utils.h
index e1e465b..7e02994 100644
--- a/gspell/gspell-utils.h
+++ b/gspell/gspell-utils.h
@@ -60,6 +60,11 @@ void         _gspell_utils_init_underline_rgba       (GdkRGBA *underline_color);
 G_GNUC_INTERNAL
 PangoAttribute *_gspell_utils_create_pango_attr_underline_color (void);
 
+G_GNUC_INTERNAL
+void           _gspell_utils_improve_word_boundaries   (const gchar  *text,
+                                                        PangoLogAttr *log_attrs,
+                                                        gint          n_attrs);
+
 G_END_DECLS
 
 #endif /* GSPELL_UTILS_H */


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