[gedit] Improved performance of not spell-checking no-spell-check
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit] Improved performance of not spell-checking no-spell-check
- Date: Sun, 3 Jan 2010 18:02:19 +0000 (UTC)
commit 2027997ed003ab53f336d58183c32a20f8e61121
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Sun Jan 3 18:35:07 2010 +0100
Improved performance of not spell-checking no-spell-check
This now uses
gtk_source_buffer_iter_forward_to_context_class_toggle to skip
parts of the file that should not be spell-checked.
plugins/spell/Makefile.am | 2 +
plugins/spell/gedit-automatic-spell-checker.c | 14 ++------
plugins/spell/gedit-spell-plugin.c | 16 +++-------
plugins/spell/gedit-spell-utils.c | 40 +++++++++++++++++++++++++
plugins/spell/gedit-spell-utils.h | 35 +++++++++++++++++++++
5 files changed, 86 insertions(+), 21 deletions(-)
---
diff --git a/plugins/spell/Makefile.am b/plugins/spell/Makefile.am
index 8d095b9..4185fe2 100644
--- a/plugins/spell/Makefile.am
+++ b/plugins/spell/Makefile.am
@@ -28,6 +28,8 @@ libspell_la_SOURCES = \
gedit-spell-language-dialog.h \
gedit-automatic-spell-checker.c \
gedit-automatic-spell-checker.h \
+ gedit-spell-utils.c \
+ gedit-spell-utils.h \
$(BUILT_SOURCES)
libspell_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
diff --git a/plugins/spell/gedit-automatic-spell-checker.c b/plugins/spell/gedit-automatic-spell-checker.c
index 2fb9629..7236272 100644
--- a/plugins/spell/gedit-automatic-spell-checker.c
+++ b/plugins/spell/gedit-automatic-spell-checker.c
@@ -41,7 +41,7 @@
#include <glib/gi18n.h>
#include "gedit-automatic-spell-checker.h"
-
+#include "gedit-spell-utils.h"
struct _GeditAutomaticSpellChecker {
GeditDocument *doc;
@@ -73,13 +73,6 @@ check_word (GeditAutomaticSpellChecker *spell, GtkTextIter *start, GtkTextIter *
{
gchar *word;
- if (gtk_source_buffer_iter_has_context_class (GTK_SOURCE_BUFFER (spell->doc),
- start,
- "no-spell-check"))
- {
- return;
- }
-
word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), start, end, FALSE);
/*
@@ -167,11 +160,12 @@ check_range (GeditAutomaticSpellChecker *spell,
{
gtk_text_iter_forward_word_end(&start);
gtk_text_iter_backward_word_start(&start);
- }
+ }
wstart = start;
- while (gtk_text_iter_compare (&wstart, &end) < 0)
+ while (gedit_spell_utils_skip_no_spell_check (&wstart, &end) &&
+ gtk_text_iter_compare (&wstart, &end) < 0)
{
gboolean inword;
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index 3c0e0bf..3665b8f 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -25,6 +25,7 @@
#endif
#include "gedit-spell-plugin.h"
+#include "gedit-spell-utils.h"
#include <string.h> /* For strlen */
@@ -409,7 +410,6 @@ goto_next_word (GeditDocument *doc)
GtkTextIter current_iter;
GtkTextIter old_current_iter;
GtkTextIter end_iter;
- gboolean wasatend;
gedit_debug (DEBUG_PLUGINS);
@@ -425,17 +425,11 @@ goto_next_word (GeditDocument *doc)
old_current_iter = current_iter;
- do
- {
- gtk_text_iter_forward_word_ends (¤t_iter, 2);
- wasatend = gtk_text_iter_compare (¤t_iter, &end_iter) >= 0;
-
- gtk_text_iter_backward_word_start (¤t_iter);
- } while (gtk_source_buffer_iter_has_context_class (GTK_SOURCE_BUFFER (doc),
- ¤t_iter,
- "no-spell-check") && !wasatend);
+ gtk_text_iter_forward_word_ends (¤t_iter, 2);
+ gtk_text_iter_backward_word_start (¤t_iter);
- if ((gtk_text_iter_compare (&old_current_iter, ¤t_iter) < 0) &&
+ if (gedit_spell_utils_skip_no_spell_check (¤t_iter, &end_iter) &&
+ (gtk_text_iter_compare (&old_current_iter, ¤t_iter) < 0) &&
(gtk_text_iter_compare (¤t_iter, &end_iter) < 0))
{
update_current (doc, gtk_text_iter_get_offset (¤t_iter));
diff --git a/plugins/spell/gedit-spell-utils.c b/plugins/spell/gedit-spell-utils.c
new file mode 100644
index 0000000..f178416
--- /dev/null
+++ b/plugins/spell/gedit-spell-utils.c
@@ -0,0 +1,40 @@
+#include "gedit-spell-utils.h"
+#include <gtksourceview/gtksourcebuffer.h>
+
+gboolean
+gedit_spell_utils_skip_no_spell_check (GtkTextIter *start,
+ GtkTextIter *end)
+{
+ GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gtk_text_iter_get_buffer (start));
+
+ while (gtk_source_buffer_iter_has_context_class (buffer, start, "no-spell-check"))
+ {
+ GtkTextIter last = *start;
+
+ if (!gtk_source_buffer_iter_forward_to_context_class_toggle (buffer, start, "no-spell-check"))
+ {
+ return FALSE;
+ }
+
+ if (gtk_text_iter_compare (start, &last) <= 0)
+ {
+ return FALSE;
+ }
+
+ gtk_text_iter_forward_word_end (start);
+ gtk_text_iter_backward_word_start (start);
+
+ if (gtk_text_iter_compare (start, &last) <= 0)
+ {
+ return FALSE;
+ }
+
+ if (gtk_text_iter_compare (start, end) >= 0)
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
diff --git a/plugins/spell/gedit-spell-utils.h b/plugins/spell/gedit-spell-utils.h
new file mode 100644
index 0000000..c5caa04
--- /dev/null
+++ b/plugins/spell/gedit-spell-utils.h
@@ -0,0 +1,35 @@
+/*
+ * gedit-spell-utils.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GEDIT_SPELL_UTILS_H__
+#define __GEDIT_SPELL_UTILS_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+gboolean gedit_spell_utils_skip_no_spell_check (GtkTextIter *start, GtkTextIter *end);
+
+G_END_DECLS
+
+#endif /* __GEDIT_SPELL_UTILS_H__ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]