From a9abc3d95fd21f0d6ddd0a96ca29c393e1972572 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 5 May 2017 21:40:00 +0200 Subject: [PATCH] chars: optimize moving a character left in the non-UTF-8 case When not in a UTF-8 locale, each character is just a single byte. --- src/chars.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/chars.c b/src/chars.c index 0eff611c..0372568d 100644 --- a/src/chars.c +++ b/src/chars.c @@ -374,10 +374,10 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) * before the one at pos. */ size_t move_mbleft(const char *buf, size_t pos) { +#ifdef ENABLE_UTF8 + if (use_utf8) { size_t before, char_len = 0; - assert(pos <= strlen(buf)); - /* There is no library function to move backward one multibyte * character. So we just start groping for one at the farthest * possible point. */ @@ -404,6 +404,9 @@ size_t move_mbleft(const char *buf, size_t pos) } return before - char_len; + } else +#endif + return (pos == 0 ? 0 : pos - 1); } /* Return the index in buf of the beginning of the multibyte character