chars: valid UTF-8 codes are at most 4 bytes long, so look only that far

This reduces the backwards searching time by a good 20 percent.
master
Benno Schulenberg 2017-05-02 10:50:43 +02:00
parent 5a3de7f117
commit f162a6a2ab
1 changed files with 2 additions and 2 deletions

View File

@ -381,10 +381,10 @@ size_t move_mbleft(const char *buf, size_t pos)
/* There is no library function to move backward one multibyte
* character. So we just start groping for one at the farthest
* possible point. */
if (pos < MAXCHARLEN)
if (pos < 4)
before = 0;
else
before = pos - MAXCHARLEN;
before = pos - 4;
while (before < pos) {
char_len = parse_mbchar(buf + before, NULL, NULL);