зеркало из https://github.com/github/ruby.git
string.c: add fastpath in str_ensure_byte_pos
If the string only contain single byte characters we can skips all the costly checks.
This commit is contained in:
Родитель
a332367dad
Коммит
3bac5f6af5
2
string.c
2
string.c
|
@ -4254,6 +4254,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
|
|||
static void
|
||||
str_ensure_byte_pos(VALUE str, long pos)
|
||||
{
|
||||
if (!single_byte_optimizable(str)) {
|
||||
const char *s = RSTRING_PTR(str);
|
||||
const char *e = RSTRING_END(str);
|
||||
const char *p = s + pos;
|
||||
|
@ -4261,6 +4262,7 @@ str_ensure_byte_pos(VALUE str, long pos)
|
|||
rb_raise(rb_eIndexError,
|
||||
"offset %ld does not land on character boundary", pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче