RJIT: Optimize String#bytesize
This commit is contained in:
parent
106cca5111
commit
32e0c97dfa
@ -2766,6 +2766,22 @@ module RubyVM::RJIT
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param jit [RubyVM::RJIT::JITState]
|
||||||
|
# @param ctx [RubyVM::RJIT::Context]
|
||||||
|
# @param asm [RubyVM::RJIT::Assembler]
|
||||||
|
def jit_rb_str_bytesize(jit, ctx, asm, argc, known_recv_class)
|
||||||
|
asm.comment('String#bytesize')
|
||||||
|
|
||||||
|
recv = ctx.stack_pop(1)
|
||||||
|
asm.mov(C_ARGS[0], recv)
|
||||||
|
asm.call(C.rb_str_bytesize)
|
||||||
|
|
||||||
|
out_opnd = ctx.stack_push
|
||||||
|
asm.mov(out_opnd, C_RET)
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
# @param jit [RubyVM::RJIT::JITState]
|
# @param jit [RubyVM::RJIT::JITState]
|
||||||
# @param ctx [RubyVM::RJIT::Context]
|
# @param ctx [RubyVM::RJIT::Context]
|
||||||
# @param asm [RubyVM::RJIT::Assembler]
|
# @param asm [RubyVM::RJIT::Assembler]
|
||||||
@ -2852,7 +2868,7 @@ module RubyVM::RJIT
|
|||||||
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_s, :jit_rb_str_to_s)
|
||||||
register_cfunc_method(String, :to_str, :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)
|
register_cfunc_method(String, :bytesize, :jit_rb_str_bytesize)
|
||||||
#register_cfunc_method(String, :<<, :jit_rb_str_concat)
|
#register_cfunc_method(String, :<<, :jit_rb_str_concat)
|
||||||
#register_cfunc_method(String, :+@, :jit_rb_str_uplus)
|
#register_cfunc_method(String, :+@, :jit_rb_str_uplus)
|
||||||
|
|
||||||
|
1
rjit_c.c
1
rjit_c.c
@ -497,6 +497,7 @@ extern void rb_vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, V
|
|||||||
extern VALUE rb_vm_throw(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t throw_state, VALUE throwobj);
|
extern VALUE rb_vm_throw(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t throw_state, VALUE throwobj);
|
||||||
extern VALUE rb_reg_new_ary(VALUE ary, int opt);
|
extern VALUE rb_reg_new_ary(VALUE ary, int opt);
|
||||||
extern void rb_vm_setclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, VALUE val, ICVARC ic);
|
extern void rb_vm_setclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, VALUE val, ICVARC ic);
|
||||||
|
extern VALUE rb_str_bytesize(VALUE str);
|
||||||
|
|
||||||
#include "rjit_c.rbinc"
|
#include "rjit_c.rbinc"
|
||||||
|
|
||||||
|
@ -607,6 +607,10 @@ module RubyVM::RJIT # :nodoc: all
|
|||||||
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_reg_nth_match) }
|
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_reg_nth_match) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def C.rb_str_bytesize
|
||||||
|
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_str_bytesize) }
|
||||||
|
end
|
||||||
|
|
||||||
def C.rb_str_concat_literals
|
def C.rb_str_concat_literals
|
||||||
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_str_concat_literals) }
|
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_str_concat_literals) }
|
||||||
end
|
end
|
||||||
|
2
string.c
2
string.c
@ -2186,7 +2186,7 @@ rb_str_length(VALUE str)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
rb_str_bytesize(VALUE str)
|
rb_str_bytesize(VALUE str)
|
||||||
{
|
{
|
||||||
return LONG2NUM(RSTRING_LEN(str));
|
return LONG2NUM(RSTRING_LEN(str));
|
||||||
|
@ -545,6 +545,7 @@ generator = BindingGenerator.new(
|
|||||||
rb_ary_clear
|
rb_ary_clear
|
||||||
rb_str_intern
|
rb_str_intern
|
||||||
rb_vm_setclassvariable
|
rb_vm_setclassvariable
|
||||||
|
rb_str_bytesize
|
||||||
],
|
],
|
||||||
types: %w[
|
types: %w[
|
||||||
CALL_DATA
|
CALL_DATA
|
||||||
|
7
yjit.c
7
yjit.c
@ -442,13 +442,6 @@ rb_iseq_opcode_at_pc(const rb_iseq_t *iseq, const VALUE *pc)
|
|||||||
return rb_vm_insn_addr2opcode((const void *)at_pc);
|
return rb_vm_insn_addr2opcode((const void *)at_pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// used by jit_rb_str_bytesize in codegen.rs
|
|
||||||
VALUE
|
|
||||||
rb_str_bytesize(VALUE str)
|
|
||||||
{
|
|
||||||
return LONG2NUM(RSTRING_LEN(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
rb_RSTRING_LEN(VALUE str)
|
rb_RSTRING_LEN(VALUE str)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user