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().
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-01-10 15:36:07 +09:00
parent 4c859e754d
commit 31f2d93657
+2 -1
View File
@@ -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;