tweaks: elide two more instances of useless character copying
Just point at the relevant characters directly instead of first copying them out.master
parent
20e122ef41
commit
8c25bd0e94
16
src/utils.c
16
src/utils.c
|
@ -193,22 +193,18 @@ void free_chararray(char **array, size_t len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_SPELLER
|
#ifdef ENABLE_SPELLER
|
||||||
/* Is the word starting at the given position in buf and of the given length
|
/* Is the word starting at the given position in 'text' and of the given
|
||||||
* a separate word? That is: is it not part of a longer word?*/
|
* length a separate word? That is: is it not part of a longer word? */
|
||||||
bool is_separate_word(size_t position, size_t length, const char *buf)
|
bool is_separate_word(size_t position, size_t length, const char *text)
|
||||||
{
|
{
|
||||||
char before[MAXCHARLEN], after[MAXCHARLEN];
|
const char *before = text + step_left(text, position);
|
||||||
size_t word_end = position + length;
|
const char *after = text + position + length;
|
||||||
|
|
||||||
/* Get the characters before and after the word, if any. */
|
|
||||||
collect_char(buf + step_left(buf, position), before);
|
|
||||||
collect_char(buf + word_end, after);
|
|
||||||
|
|
||||||
/* If the word starts at the beginning of the line OR the character before
|
/* If the word starts at the beginning of the line OR the character before
|
||||||
* the word isn't a letter, and if the word ends at the end of the line OR
|
* the word isn't a letter, and if the word ends at the end of the line OR
|
||||||
* the character after the word isn't a letter, we have a whole word. */
|
* the character after the word isn't a letter, we have a whole word. */
|
||||||
return ((position == 0 || !is_alpha_char(before)) &&
|
return ((position == 0 || !is_alpha_char(before)) &&
|
||||||
(buf[word_end] == '\0' || !is_alpha_char(after)));
|
(*after == '\0' || !is_alpha_char(after)));
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_SPELLER */
|
#endif /* ENABLE_SPELLER */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue