Skip to content

Commit 2fc357c

Browse files
committed
YJIT: Avoid std::ffi::CString with rb_intern2() during boot
Fewer allocations on boot, too. Suggested-by: ruby#12217
1 parent 36a9830 commit 2fc357c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

yjit/src/codegen.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10737,13 +10737,12 @@ pub fn yjit_reg_method_codegen_fns() {
1073710737
/// and do not make method calls.
1073810738
///
1073910739
/// See also: [lookup_cfunc_codegen].
10740-
fn reg_method_codegen(klass: VALUE, mid_str: &str, gen_fn: MethodGenFn) {
10741-
let id_string = std::ffi::CString::new(mid_str).expect("couldn't convert to CString!");
10742-
let mid = unsafe { rb_intern(id_string.as_ptr()) };
10740+
fn reg_method_codegen(klass: VALUE, method_name: &str, gen_fn: MethodGenFn) {
10741+
let mid = unsafe { rb_intern2(method_name.as_ptr().cast(), method_name.len().try_into().unwrap()) };
1074310742
let me = unsafe { rb_method_entry_at(klass, mid) };
1074410743

1074510744
if me.is_null() {
10746-
panic!("undefined optimized method!: {mid_str}");
10745+
panic!("undefined optimized method!: {method_name}");
1074710746
}
1074810747

1074910748
// For now, only cfuncs are supported (me->cme cast fine since it's just me->def->type).

0 commit comments

Comments
 (0)