commit 0dcac9188f9da7d98e31aa12ad2288bc9c83f796
parent 1c010d8ec9a788a3065f52331daee584fda1c158
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 29 Mar 2021 20:01:46 +0200
tweaks: simplify two fragments of code, eliding useless character copying
Diffstat:
2 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/src/chars.c b/src/chars.c
@@ -648,20 +648,13 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer)
#endif /* !NANO_TINY */
#if defined(ENABLE_NANORC) && (!defined(NANO_TINY) || defined(ENABLE_JUSTIFY))
-/* Return TRUE if the given string contains at least one blank character,
- * and FALSE otherwise. */
+/* Return TRUE if the given string contains at least one blank character. */
bool has_blank_char(const char *string)
{
- char symbol[MAXCHARLEN];
-
- while (*string != '\0') {
- string += collect_char(string, symbol);
-
- if (is_blank_char(symbol))
- return TRUE;
- }
+ while (*string != '\0' && !is_blank_char(string))
+ string += char_length(string);
- return FALSE;
+ return *string;
}
#endif /* ENABLE_NANORC && (!NANO_TINY || ENABLE_JUSTIFY) */
diff --git a/src/text.c b/src/text.c
@@ -1453,21 +1453,12 @@ ssize_t break_line(const char *textstart, ssize_t goal, bool snap_at_nl)
* "indentation" of a line is the leading consecutive whitespace. */
size_t indent_length(const char *line)
{
- size_t len = 0;
- char onechar[MAXCHARLEN];
- int charlen;
-
- while (*line != '\0') {
- charlen = collect_char(line, onechar);
+ const char *start = line;
- if (!is_blank_char(onechar))
- break;
-
- line += charlen;
- len += charlen;
- }
+ while (*line != '\0' && is_blank_char(line))
+ line += char_length(line);
- return len;
+ return (line - start);
}
#endif