From 575609f3b94881e187f79114d0d07cc442ea01e4 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 10 May 2026 01:30:29 +0900 Subject: [PATCH] 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 --- include/mruby.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/mruby.h b/include/mruby.h index e4765781e..65fe84778 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -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. */