From 023ff119fb511e262e7cd64b8abb7482720ac4a6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 22 Apr 2020 18:58:45 -0700 Subject: [PATCH] Tweak multibyte parsing loops * src/character.c (parse_str_as_multibyte, str_as_multibyte): Let the fast loop run a little longer, fixing what appears to be an off-by-1 performance nit. --- src/character.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/character.c b/src/character.c index da09e77e131..edcec5f1c79 100644 --- a/src/character.c +++ b/src/character.c @@ -512,7 +512,7 @@ parse_str_as_multibyte (const unsigned char *str, ptrdiff_t len, if (len >= MAX_MULTIBYTE_LENGTH) { - const unsigned char *adjusted_endp = endp - MAX_MULTIBYTE_LENGTH; + const unsigned char *adjusted_endp = endp - (MAX_MULTIBYTE_LENGTH - 1); while (str < adjusted_endp) { int n = multibyte_length (str, NULL, false, false); @@ -556,7 +556,7 @@ str_as_multibyte (unsigned char *str, ptrdiff_t len, ptrdiff_t nbytes, if (nbytes >= MAX_MULTIBYTE_LENGTH) { - unsigned char *adjusted_endp = endp - MAX_MULTIBYTE_LENGTH; + unsigned char *adjusted_endp = endp - (MAX_MULTIBYTE_LENGTH - 1); while (p < adjusted_endp) { int n = multibyte_length (p, NULL, false, false); @@ -585,7 +585,7 @@ str_as_multibyte (unsigned char *str, ptrdiff_t len, ptrdiff_t nbytes, if (nbytes >= MAX_MULTIBYTE_LENGTH) { - unsigned char *adjusted_endp = endp - MAX_MULTIBYTE_LENGTH; + unsigned char *adjusted_endp = endp - (MAX_MULTIBYTE_LENGTH - 1); while (p < adjusted_endp) { int n = multibyte_length (p, NULL, false, false); -- 2.39.2