From 8c25bd0e948c2f3b42f0150111163f82cfe4543a Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 2 Apr 2021 16:34:41 +0200 Subject: [PATCH] tweaks: elide two more instances of useless character copying Just point at the relevant characters directly instead of first copying them out. --- src/utils.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/utils.c b/src/utils.c index 99d96257..ed3d68b6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -193,22 +193,18 @@ void free_chararray(char **array, size_t len) #endif #ifdef ENABLE_SPELLER -/* Is the word starting at the given position in buf and of the given 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) +/* Is the word starting at the given position in 'text' and of the given + * 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 *text) { - char before[MAXCHARLEN], after[MAXCHARLEN]; - size_t word_end = 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); + const char *before = text + step_left(text, position); + const char *after = text + position + length; /* 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 character after the word isn't a letter, we have a whole word. */ return ((position == 0 || !is_alpha_char(before)) && - (buf[word_end] == '\0' || !is_alpha_char(after))); + (*after == '\0' || !is_alpha_char(after))); } #endif /* ENABLE_SPELLER */