Skip to content

Commit

Permalink
spellcheck: Use direct buffer access instead of deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Feb 20, 2016
1 parent aecfa59 commit 2c48166
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions spellcheck/src/gui.c
Expand Up @@ -179,8 +179,8 @@ static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
{
gint startword, endword, i, doc_len;
ScintillaObject *sci;
GString *str;
gboolean ignore = GPOINTER_TO_INT(gdata);
gint click_word_len;

if (clickinfo.doc == NULL || clickinfo.word == NULL || clickinfo.pos == -1)
return;
Expand All @@ -195,7 +195,7 @@ static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)

/* Remove all indicators on the added/ignored word */
sci = clickinfo.doc->editor->sci;
str = g_string_sized_new(256);
click_word_len = (gint) strlen(clickinfo.word);
doc_len = sci_get_length(sci);
for (i = 0; i < doc_len; i++)
{
Expand All @@ -206,17 +206,18 @@ static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
if (startword == endword)
continue;

if (str->len < (guint)(endword - startword + 1))
str = g_string_set_size(str, endword - startword + 1);
sci_get_text_range(sci, startword, endword, str->str);
if (click_word_len == endword - startword)
{
const gchar *ptr = (const gchar *) scintilla_send_message(sci,
SCI_GETRANGEPOINTER, startword, endword - startword);

if (strcmp(str->str, clickinfo.word) == 0)
sci_indicator_clear(sci, startword, endword - startword);
if (strncmp(ptr, clickinfo.word, click_word_len) == 0)
sci_indicator_clear(sci, startword, endword - startword);
}

i = endword;
}
}
g_string_free(str, TRUE);
}


Expand Down

1 comment on commit 2c48166

@b4n
Copy link
Member Author

@b4n b4n commented on 2c48166 Feb 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a fair bit faster as the word is only even fetched only if its length would match the clickpos one's, in case the strcmp() would have failed anyway. And as we know the length, we can use strncmp() and then any pointer (without necessarily a trailing \0).

Also, the gap is not very likely to be in the middle of a word, so unlikely to have to move. And anyway, would move at worse once.

Please sign in to comment.