array.c (mrb_ary_times): avoid multiple calls to mrb_get_args()

This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-01-24 15:23:30 +09:00
parent d9bf3235d2
commit d1449c2622
+4 -4
View File
@@ -450,16 +450,16 @@ mrb_ary_times(mrb_state *mrb, mrb_value self)
{
struct RArray *a1 = mrb_ary_ptr(self);
struct RArray *a2;
mrb_value *ptr, sep, tmp;
mrb_value *ptr, arg, tmp;
mrb_int times, len1;
mrb_get_args(mrb, "o", &sep);
tmp = mrb_check_string_type(mrb, sep);
arg = mrb_get_arg1(mrb);
tmp = mrb_check_string_type(mrb, arg);
if (!mrb_nil_p(tmp)) {
return mrb_ary_join(mrb, self, tmp);
}
mrb_get_args(mrb, "i", &times);
times = mrb_as_int(mrb, arg);
if (times < 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argument");
}