Remove function call for String#bytesize (#8389)

* Remove function call for String#bytesize

String size is stored in a consistent location, so we can eliminate the
function call.

* Update yjit/src/codegen.rs

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
This commit is contained in:
Aaron Patterson 2023-09-07 06:54:05 -07:00 committed by GitHub
parent 0c8928721e
commit 0adca625ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2023-09-07 13:54:24 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>
2 changed files with 13 additions and 3 deletions

View File

@ -4697,10 +4697,21 @@ fn jit_rb_str_bytesize(
asm.comment("String#bytesize");
let recv = asm.stack_pop(1);
let ret_opnd = asm.ccall(rb_str_bytesize as *const u8, vec![recv]);
asm.comment("get string length");
let str_len_opnd = Opnd::mem(
std::os::raw::c_long::BITS as u8,
asm.load(recv),
RUBY_OFFSET_RSTRING_LEN as i32,
);
let len = asm.load(str_len_opnd);
let shifted_val = asm.lshift(len, Opnd::UImm(1));
let out_val = asm.or(shifted_val, Opnd::UImm(RUBY_FIXNUM_FLAG as u64));
let out_opnd = asm.stack_push(Type::Fixnum);
asm.mov(out_opnd, ret_opnd);
asm.mov(out_opnd, out_val);
true
}

View File

@ -135,7 +135,6 @@ extern "C" {
ic: ICVARC,
) -> VALUE;
pub fn rb_vm_ic_hit_p(ic: IC, reg_ep: *const VALUE) -> bool;
pub fn rb_str_bytesize(str: VALUE) -> VALUE;
}
// Renames