From 31f2d936573e90059cf413f07705aa1d29b44fdd Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 10 Jan 2024 15:36:07 +0900 Subject: [PATCH] string.c (bytes2chars): skip calling mrb_utf8len() if possible If (ch < 0x80) the length of the character (in bytes) should be 1, so we don't have to call mrb_utf8len(). --- src/string.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/string.c b/src/string.c index 411de76e6..c6f419247 100644 --- a/src/string.c +++ b/src/string.c @@ -358,7 +358,8 @@ bytes2chars(mrb_value s, mrb_int bi) mrb_int i; for (i = 0; p < pivot; i++) { - p += mrb_utf8len(p, e); + if ((*p & 0x80) == 0) p++; + else p += mrb_utf8len(p, e); } if (p != pivot) return -1; return i;