mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
RJIT: Optimize String#empty?
This commit is contained in:
parent
ca9355e173
commit
106cca5111
3 changed files with 50 additions and 1 deletions
|
@ -2729,6 +2729,29 @@ module RubyVM::RJIT
|
|||
true
|
||||
end
|
||||
|
||||
# @param jit [RubyVM::RJIT::JITState]
|
||||
# @param ctx [RubyVM::RJIT::Context]
|
||||
# @param asm [RubyVM::RJIT::Assembler]
|
||||
def jit_rb_str_empty_p(jit, ctx, asm, argc, known_recv_class)
|
||||
# Assume same offset to len embedded or not so we can use one code path to read the length
|
||||
assert_equal(C.RString.offsetof(:as, :heap, :len), C.RString.offsetof(:as, :embed, :len))
|
||||
|
||||
recv_opnd = ctx.stack_pop(1)
|
||||
out_opnd = ctx.stack_push
|
||||
|
||||
asm.comment('get string length')
|
||||
asm.mov(:rax, recv_opnd)
|
||||
str_len_opnd = [:rax, C.RString.offsetof(:as, :heap, :len)]
|
||||
|
||||
asm.cmp(str_len_opnd, 0)
|
||||
asm.mov(:rax, Qfalse)
|
||||
asm.mov(:rcx, Qtrue)
|
||||
asm.cmove(:rax, :rcx)
|
||||
asm.mov(out_opnd, :rax)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
# @param jit [RubyVM::RJIT::JITState]
|
||||
# @param ctx [RubyVM::RJIT::Context]
|
||||
# @param asm [RubyVM::RJIT::Assembler]
|
||||
|
@ -2826,7 +2849,7 @@ module RubyVM::RJIT
|
|||
register_cfunc_method(Integer, :===, :jit_rb_int_equal)
|
||||
|
||||
# rb_str_to_s() methods in string.c
|
||||
#register_cfunc_method(String, :empty?, :jit_rb_str_empty_p)
|
||||
register_cfunc_method(String, :empty?, :jit_rb_str_empty_p)
|
||||
register_cfunc_method(String, :to_s, :jit_rb_str_to_s)
|
||||
register_cfunc_method(String, :to_str, :jit_rb_str_to_s)
|
||||
#register_cfunc_method(String, :bytesize, :jit_rb_str_bytesize)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue