Skip to content

Commit

Permalink
spellcheck: Drop use of deprecated sci_get_text_range()
Browse files Browse the repository at this point in the history
Naive replacement leads to allocating the buffer on each call, but it
should not be a concern as the previous commit dropped more useless
allocations yet nobody complained before.
  • Loading branch information
b4n committed Feb 20, 2016
1 parent 7988686 commit f5871f7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions spellcheck/src/speller.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
gint suggestions_found = 0;
gint wordchars_len;
gchar *wordchars;
GString *str;

g_return_val_if_fail(sc_speller_dict != NULL, 0);
g_return_val_if_fail(doc != NULL, 0);
Expand All @@ -223,35 +222,32 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
}

str = g_string_sized_new(256);

pos_start = sci_get_position_from_line(doc->editor->sci, line_number);
pos_end = sci_get_position_from_line(doc->editor->sci, line_number + 1);

while (pos_start < pos_end)
{
gchar *word;

wstart = scintilla_send_message(doc->editor->sci, SCI_WORDSTARTPOSITION, pos_start, TRUE);
wend = scintilla_send_message(doc->editor->sci, SCI_WORDENDPOSITION, wstart, FALSE);
if (wstart == wend)
break;

/* ensure the string has enough allocated memory */
if (str->len < (guint)(wend - wstart))
g_string_set_size(str, wend - wstart);

sci_get_text_range(doc->editor->sci, wstart, wend, str->str);
word = sci_get_contents_range(doc->editor->sci, wstart, wend);

suggestions_found += sc_speller_check_word(doc, line_number, str->str, wstart, wend);
suggestions_found += sc_speller_check_word(doc, line_number, word, wstart, wend);

pos_start = wend + 1;

g_free(word);
}

/* reset wordchars for the current document */
wordchars[wordchars_len] = '\0';
scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);

g_free(wordchars);
g_string_free(str, TRUE);
return suggestions_found;
}

Expand Down

1 comment on commit f5871f7

@b4n
Copy link
Member Author

@b4n b4n commented on f5871f7 Feb 20, 2016

Choose a reason for hiding this comment

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

This is a little more questionable and basically just drop use of the deprecated sci_get_contents_range(), making the code slightly simpler and slightly less optimized. But well, as the commit message says I doubt it's an issue.

Please sign in to comment.