From 140bf4d8a035f669b24541ff71144d086588f7b5 Mon Sep 17 00:00:00 2001 From: Satoshi Tagomori Date: Tue, 12 Aug 2025 11:34:30 +0900 Subject: [PATCH] localize rb_vm_t and minimize times of GET_VM() calls --- load.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/load.c b/load.c index 6f3da288aa..cab3cdf3b2 100644 --- a/load.c +++ b/load.c @@ -1149,21 +1149,23 @@ search_required(const rb_namespace_t *ns, VALUE fname, volatile VALUE *path, fea // Check if it's a statically linked extension when // not already a feature and not found as a dynamic library. - rb_vm_t *vm = GET_VM(); - if (!ft && type != loadable_ext_rb && vm->static_ext_inits) { - VALUE lookup_name = tmp; - // Append ".so" if not already present so for example "etc" can find "etc.so". - // We always register statically linked extensions with a ".so" extension. - // See encinit.c and extinit.c (generated at build-time). - if (!ext) { - lookup_name = rb_str_dup(lookup_name); - rb_str_cat_cstr(lookup_name, ".so"); - } - ftptr = RSTRING_PTR(lookup_name); - if (st_lookup(vm->static_ext_inits, (st_data_t)ftptr, NULL)) { - *path = rb_filesystem_str_new_cstr(ftptr); - RB_GC_GUARD(lookup_name); - return 's'; + if (!ft && type != loadable_ext_rb) { + rb_vm_t *vm = GET_VM(); + if (vm->static_ext_inits) { + VALUE lookup_name = tmp; + // Append ".so" if not already present so for example "etc" can find "etc.so". + // We always register statically linked extensions with a ".so" extension. + // See encinit.c and extinit.c (generated at build-time). + if (!ext) { + lookup_name = rb_str_dup(lookup_name); + rb_str_cat_cstr(lookup_name, ".so"); + } + ftptr = RSTRING_PTR(lookup_name); + if (st_lookup(vm->static_ext_inits, (st_data_t)ftptr, NULL)) { + *path = rb_filesystem_str_new_cstr(ftptr); + RB_GC_GUARD(lookup_name); + return 's'; + } } }