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.
master
Benno Schulenberg 2017-05-05 21:40:00 +02:00
parent 09cabcad5d
commit a9abc3d95f
1 changed files with 5 additions and 2 deletions

View File

@ -374,10 +374,10 @@ int parse_mbchar(const char *buf, char *chr, size_t *col)
* before the one at pos. */ * before the one at pos. */
size_t move_mbleft(const char *buf, size_t pos) size_t move_mbleft(const char *buf, size_t pos)
{ {
#ifdef ENABLE_UTF8
if (use_utf8) {
size_t before, char_len = 0; size_t before, char_len = 0;
assert(pos <= strlen(buf));
/* There is no library function to move backward one multibyte /* There is no library function to move backward one multibyte
* character. So we just start groping for one at the farthest * character. So we just start groping for one at the farthest
* possible point. */ * possible point. */
@ -404,6 +404,9 @@ size_t move_mbleft(const char *buf, size_t pos)
} }
return before - char_len; return before - char_len;
} else
#endif
return (pos == 0 ? 0 : pos - 1);
} }
/* Return the index in buf of the beginning of the multibyte character /* Return the index in buf of the beginning of the multibyte character