Use `mrb_get_argc()` to improve performance.

parent ea6e1b00
......@@ -138,9 +138,8 @@ mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
mrb_ary_modify(mrb, a);
if (mrb_get_argc(mrb) == 1) {
mrb_value index;
mrb_value index = mrb_get_arg1(mrb);
mrb_get_args(mrb, "o|i", &index, &len);
switch (mrb_type(index)) {
case MRB_TT_RANGE:
if (mrb_range_beg_len(mrb, index, &i, &len, ARY_LEN(a), TRUE) == MRB_RANGE_OK) {
......
......@@ -2885,15 +2885,18 @@ mrb_str_setbyte(mrb_state *mrb, mrb_value str)
static mrb_value
mrb_str_byteslice(mrb_state *mrb, mrb_value str)
{
mrb_value a1, a2;
mrb_value a1;
mrb_int str_len = RSTRING_LEN(str), beg, len;
mrb_bool empty = TRUE;
if (mrb_get_args(mrb, "o|o", &a1, &a2) == 2) {
beg = mrb_fixnum(mrb_to_int(mrb, a1));
len = mrb_fixnum(mrb_to_int(mrb, a2));
}
else if (mrb_range_p(a1)) {
len = mrb_get_argc(mrb);
switch (len) {
case 2:
mrb_get_args(mrb, "ii", &beg, &len);
break;
case 1:
a1 = mrb_get_arg1(mrb);
if (mrb_range_p(a1)) {
if (mrb_range_beg_len(mrb, a1, &beg, &len, str_len, TRUE) != MRB_RANGE_OK) {
return mrb_nil_value();
}
......@@ -2903,7 +2906,11 @@ mrb_str_byteslice(mrb_state *mrb, mrb_value str)
len = 1;
empty = FALSE;
}
break;
default:
mrb_argnum_error(mrb, len, 1, 2);
break;
}
if (mrb_str_beg_len(str_len, &beg, &len) && (empty || len != 0)) {
return mrb_str_byte_subseq(mrb, str, beg, len);
}
......
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