string.c (bytes2chars): skip scanning if the string is ASCII only

This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-01-10 14:40:39 +09:00
parent df0a5e838d
commit 4c859e754d
+4
View File
@@ -348,6 +348,10 @@ chars2bytes(mrb_value s, mrb_int off, mrb_int idx)
static mrb_int
bytes2chars(mrb_value s, mrb_int bi)
{
if (RSTR_ASCII_P(mrb_str_ptr(s))) {
return bi;
}
const char *p = RSTRING_PTR(s);
const char *e = RSTRING_END(s);
const char *pivot = p + bi;