From c57d040e999a91cdf5d799ccf84aa6777a26777f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 11 Jun 2019 19:21:47 +0200 Subject: [PATCH] tweaks: don't bother calling mblen() in a non-UTF-8 build There is no need, because in non-UTF-8 encodings nano treats each single byte as one character anyway. --- src/chars.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chars.c b/src/chars.c index d8298c52..076f3f08 100644 --- a/src/chars.c +++ b/src/chars.c @@ -253,12 +253,14 @@ char *make_mbchar(long chr, int *chr_mb_len) /* Return the length (in bytes) of the character located at *pointer. */ int char_length(const char *pointer) { +#ifdef ENABLE_UTF8 /* If possibly a multibyte character, get its length; otherwise, it's 1. */ if ((signed char)*pointer < 0) { int length = mblen(pointer, MAXCHARLEN); - return (length > 0 ? length : 1); + return (length < 0 ? 1 : length); } else +#endif return 1; } @@ -491,11 +493,13 @@ size_t mbstrlen(const char *pointer) size_t count = 0; while (*pointer != '\0') { +#ifdef ENABLE_UTF8 if ((signed char)*pointer < 0) { int length = mblen(pointer, MAXCHARLEN); pointer += (length < 0 ? 1 : length); } else +#endif pointer++; count++;