array.c: avoid slower mrb_get_args() if possible

This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-01-25 14:10:03 +09:00
parent 37da677cc8
commit 4e5be5a288
2 changed files with 4 additions and 5 deletions
+1 -2
View File
@@ -89,8 +89,7 @@ mrb_ary_rassoc(mrb_state *mrb, mrb_value ary)
static mrb_value
mrb_ary_at(mrb_state *mrb, mrb_value ary)
{
mrb_int pos;
mrb_get_args(mrb, "i", &pos);
mrb_int pos = mrb_as_int(mrb, mrb_get_arg1(mrb));
return mrb_ary_entry(ary, pos);
}
+3 -3
View File
@@ -612,12 +612,12 @@ mrb_ary_shift(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_ary_shift_m(mrb_state *mrb, mrb_value self)
{
mrb_int n;
if (mrb_get_args(mrb, "|i", &n) == 0) {
if (mrb_get_argc(mrb) == 0) {
return mrb_ary_shift(mrb, self);
}
mrb_int n = mrb_as_int(mrb, mrb_get_arg1(mrb));
struct RArray *a = mrb_ary_ptr(self);
mrb_int len = ARY_LEN(a);
mrb_value val;
@@ -1061,7 +1061,7 @@ mrb_ary_delete_at(mrb_state *mrb, mrb_value self)
mrb_value *ptr;
mrb_int len, alen;
mrb_get_args(mrb, "i", &index);
index = mrb_as_int(mrb, mrb_get_arg1(mrb));
alen = ARY_LEN(a);
if (index < 0) index += alen;
if (index < 0 || alen <= index) return mrb_nil_value();