Commit 73c086b4 authored by Patrick Pokatilo's avatar Patrick Pokatilo

Sacrifice some micro-optimization to remove duplicate code

parent c19f5efa
...@@ -309,36 +309,21 @@ ecall(mrb_state *mrb, int i) ...@@ -309,36 +309,21 @@ ecall(mrb_state *mrb, int i)
mrb_value mrb_value
mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, mrb_int argc, ...) mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, mrb_int argc, ...)
{ {
mrb_value argv[MRB_FUNCALL_ARGC_MAX];
va_list ap;
mrb_int i;
mrb_sym mid = mrb_intern_cstr(mrb, name); mrb_sym mid = mrb_intern_cstr(mrb, name);
if (argc == 0) { if (argc > MRB_FUNCALL_ARGC_MAX) {
return mrb_funcall_argv(mrb, self, mid, 0, 0); mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=" TO_STR(MRB_FUNCALL_ARGC_MAX) ")");
} }
else if (argc == 1) {
mrb_value v;
va_list ap;
va_start(ap, argc);
v = va_arg(ap, mrb_value);
va_end(ap);
return mrb_funcall_argv(mrb, self, mid, 1, &v);
}
else {
mrb_value argv[MRB_FUNCALL_ARGC_MAX];
va_list ap;
mrb_int i;
if (argc > MRB_FUNCALL_ARGC_MAX) { va_start(ap, argc);
mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=" TO_STR(MRB_FUNCALL_ARGC_MAX) ")"); for (i = 0; i < argc; i++) {
} argv[i] = va_arg(ap, mrb_value);
va_start(ap, argc);
for (i = 0; i < argc; i++) {
argv[i] = va_arg(ap, mrb_value);
}
va_end(ap);
return mrb_funcall_argv(mrb, self, mid, argc, argv);
} }
va_end(ap);
return mrb_funcall_argv(mrb, self, mid, argc, argv);
} }
mrb_value mrb_value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment