зеркало из https://github.com/github/ruby.git
Optimize Integer#[]
This commit is contained in:
Родитель
34f2ab1f3c
Коммит
6d59cac4ad
|
@ -1778,6 +1778,29 @@ module RubyVM::MJIT
|
|||
true
|
||||
end
|
||||
|
||||
# @param jit [RubyVM::MJIT::JITState]
|
||||
# @param ctx [RubyVM::MJIT::Context]
|
||||
# @param asm [RubyVM::MJIT::Assembler]
|
||||
def jit_rb_int_aref(jit, ctx, asm, argc)
|
||||
return false if argc != 1
|
||||
return false unless two_fixnums_on_stack?(jit)
|
||||
|
||||
side_exit = side_exit(jit, ctx)
|
||||
guard_two_fixnums(jit, ctx, asm, side_exit)
|
||||
|
||||
asm.comment('rb_int_aref')
|
||||
y_opnd = ctx.stack_pop
|
||||
x_opnd = ctx.stack_pop
|
||||
|
||||
asm.mov(C_ARGS[0], x_opnd)
|
||||
asm.mov(C_ARGS[1], y_opnd)
|
||||
asm.call(C.rb_fix_aref)
|
||||
|
||||
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]
|
||||
|
@ -1810,6 +1833,7 @@ module RubyVM::MJIT
|
|||
register_cfunc_method(Integer, :===, :jit_rb_int_equal)
|
||||
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(Array, :<<, :jit_rb_ary_push)
|
||||
end
|
||||
|
|
|
@ -297,6 +297,13 @@ module RubyVM::MJIT # :nodoc: all
|
|||
Primitive.cexpr! 'SIZET2NUM((size_t)rb_ary_push)'
|
||||
end
|
||||
|
||||
def rb_fix_aref
|
||||
Primitive.cstmt! %{
|
||||
extern VALUE rb_fix_aref(VALUE fix, VALUE idx);
|
||||
return SIZET2NUM((size_t)rb_fix_aref);
|
||||
}
|
||||
end
|
||||
|
||||
#========================================================================================
|
||||
#
|
||||
# Old stuff
|
||||
|
|
Загрузка…
Ссылка в новой задаче