Skip to content

Commit 68c0abd

Browse files
committed
pp_reverse: Use isUTF8_CHAR() for validity check
The code was converting a UTF-8 single character string to its code point, just to find out if the string was wellformed or not. It had no need of the returned code point. It is more efficient to just use the function that checks for validity without trying to get the code point. The validity checking function returns 0 on failure; else how many bytes were in the string. Use this value instead of calling UTF8SKIP to re-derive it. And the former function utf8_to_uvchr_buf() is discouraged from use anyway. This commit removes the final core use of the discouraged _uvchr functions,
1 parent 939314c commit 68c0abd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6636,10 +6636,11 @@ PP_wrapped(pp_reverse, 0, 1)
66366636
continue;
66376637
}
66386638
else {
6639-
if (!utf8_to_uvchr_buf(s, send, 0))
6639+
Size_t advance = isUTF8_CHAR(s, send);
6640+
if (advance == 0)
66406641
break;
66416642
up = (char*)s;
6642-
s += UTF8SKIP(s);
6643+
s += advance;
66436644
down = (char*)(s - 1);
66446645
/* reverse this character */
66456646
while (down > up) {

0 commit comments

Comments
 (0)