mruby.h: add mrb_funcall_argv1/argv2 inline helpers

mrb_funcall_id() always reserves a 16-element argv buffer on its
stack frame regardless of the actual argument count. The two new
static inline wrappers allocate exactly one or two argument slots,
saving 100-220 bytes of stack per call after inlining (the savings
depend on mrb_value size under the active boxing configuration).

close #5804

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-05-10 01:30:29 +09:00
parent b4f6450509
commit 575609f3b9
+15
View File
@@ -1182,6 +1182,21 @@ MRB_API mrb_value mrb_funcall_id(mrb_state *mrb, mrb_value val, mrb_sym mid, mrb
* @see mrb_funcall
*/
MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv);
/*
* Convenience wrappers for `mrb_funcall_argv` with a fixed argument count.
* Avoids the 16-slot fixed argv buffer used by the variadic `mrb_funcall_id`.
*/
static inline mrb_value
mrb_funcall_argv1(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_value a1)
{
return mrb_funcall_argv(mrb, val, name, 1, &a1);
}
static inline mrb_value
mrb_funcall_argv2(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_value a1, mrb_value a2)
{
const mrb_value argv[] = { a1, a2 };
return mrb_funcall_argv(mrb, val, name, 2, argv);
}
/**
* Call existing Ruby functions with a block.
*/