Use `mrb_get_argc()` to improve performance.

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