[geany/geany-plugins] f5871f: spellcheck: Drop use of deprecated sci_get_text_range()
Colomban Wendling
git-noreply at xxxxx
Sat Feb 20 21:52:48 UTC 2016
Branch: refs/heads/master
Author: Colomban Wendling <ban at herbesfolles.org>
Committer: Colomban Wendling <ban at herbesfolles.org>
Date: Sat, 20 Feb 2016 21:52:48 UTC
Commit: f5871f7961b9de6b93c76e49a5c36040fd0a2796
https://github.com/geany/geany-plugins/commit/f5871f7961b9de6b93c76e49a5c36040fd0a2796
Log Message:
-----------
spellcheck: Drop use of deprecated sci_get_text_range()
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.
Modified Paths:
--------------
spellcheck/src/speller.c
Modified: spellcheck/src/speller.c
16 lines changed, 6 insertions(+), 10 deletions(-)
===================================================================
@@ -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);
@@ -223,27 +222,25 @@ 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 */
@@ -251,7 +248,6 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
g_free(wordchars);
- g_string_free(str, TRUE);
return suggestions_found;
}
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list