Remove unnecessary inline function `ary_elt`.

And the function does not conform the naming convention anyway.
parent 67e2dddb
......@@ -276,15 +276,6 @@ MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
*/
MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
static inline mrb_value
ary_elt(mrb_value ary, mrb_int offset)
{
if (offset < 0 || RARRAY_LEN(ary) <= offset) {
return mrb_nil_value();
}
return RARRAY_PTR(ary)[offset];
}
MRB_END_DECL
#endif /* MRUBY_ARRAY_H */
......@@ -127,19 +127,20 @@ mrb_ary_to_h(mrb_state *mrb, mrb_value ary)
hash = mrb_hash_new_capa(mrb, 0);
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = mrb_check_array_type(mrb, RARRAY_PTR(ary)[i]);
mrb_value elt = RARRAY_PTR(ary)[i];
v = mrb_check_array_type(mrb, elt);
if (mrb_nil_p(v)) {
mrb_raisef(mrb, E_TYPE_ERROR, "wrong element type %S at %S (expected array)",
mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, ary_elt(ary, i))),
mrb_fixnum_value(i)
mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, elt)),
mrb_fixnum_value(i)
);
}
if (RARRAY_LEN(v) != 2) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong array length at %S (expected 2, was %S)",
mrb_fixnum_value(i),
mrb_fixnum_value(RARRAY_LEN(v))
mrb_fixnum_value(i),
mrb_fixnum_value(RARRAY_LEN(v))
);
}
......
......@@ -1074,7 +1074,10 @@ mrb_ary_entry(mrb_value ary, mrb_int offset)
if (offset < 0) {
offset += RARRAY_LEN(ary);
}
return ary_elt(ary, offset);
if (offset < 0 || RARRAY_LEN(ary) <= offset) {
return mrb_nil_value();
}
return RARRAY_PTR(ary)[offset];
}
static 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