зеркало из https://github.com/github/ruby.git
Optimize String#getbyte
This commit is contained in:
Родитель
31babc5cea
Коммит
f0218303e0
|
@ -2278,6 +2278,24 @@ module RubyVM::MJIT
|
|||
false
|
||||
end
|
||||
|
||||
# @param jit [RubyVM::MJIT::JITState]
|
||||
# @param ctx [RubyVM::MJIT::Context]
|
||||
# @param asm [RubyVM::MJIT::Assembler]
|
||||
def jit_rb_str_getbyte(jit, ctx, asm, argc, _known_recv_class)
|
||||
return false if argc != 1
|
||||
asm.comment('rb_str_getbyte')
|
||||
|
||||
index_opnd = ctx.stack_pop
|
||||
str_opnd = ctx.stack_pop
|
||||
asm.mov(C_ARGS[0], str_opnd)
|
||||
asm.mov(C_ARGS[1], index_opnd)
|
||||
asm.call(C.rb_str_getbyte)
|
||||
|
||||
ret_opnd = ctx.stack_push
|
||||
asm.mov(ret_opnd, C_RET)
|
||||
true
|
||||
end
|
||||
|
||||
# @param jit [RubyVM::MJIT::JITState]
|
||||
# @param ctx [RubyVM::MJIT::Context]
|
||||
# @param asm [RubyVM::MJIT::Assembler]
|
||||
|
@ -2364,6 +2382,7 @@ module RubyVM::MJIT
|
|||
register_cfunc_method(Integer, :*, :jit_rb_int_mul)
|
||||
register_cfunc_method(Integer, :/, :jit_rb_int_div)
|
||||
register_cfunc_method(Integer, :[], :jit_rb_int_aref)
|
||||
register_cfunc_method(String, :getbyte, :jit_rb_str_getbyte)
|
||||
end
|
||||
|
||||
def register_cfunc_method(klass, mid_sym, func)
|
||||
|
|
|
@ -420,6 +420,13 @@ module RubyVM::MJIT # :nodoc: all
|
|||
rb_proc_t.new(proc_t_addr)
|
||||
end
|
||||
|
||||
def rb_str_getbyte
|
||||
Primitive.cstmt! %{
|
||||
extern VALUE rb_str_getbyte(VALUE str, VALUE index);
|
||||
return SIZET2NUM((size_t)rb_str_getbyte);
|
||||
}
|
||||
end
|
||||
|
||||
#========================================================================================
|
||||
#
|
||||
# Old stuff
|
||||
|
|
2
string.c
2
string.c
|
@ -6072,7 +6072,7 @@ rb_str_chr(VALUE str)
|
|||
*
|
||||
* Related: String#setbyte.
|
||||
*/
|
||||
static VALUE
|
||||
VALUE
|
||||
rb_str_getbyte(VALUE str, VALUE index)
|
||||
{
|
||||
long pos = NUM2LONG(index);
|
||||
|
|
Загрузка…
Ссылка в новой задаче