1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

compile.c: replaced switch by TYPE

* compile.c (int_param): prefer FIXNUM_P and NIL_P to switch by
  TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-09-09 09:16:56 +00:00
parent 0471781b2a
commit 6c3c48e3d5

View file

@ -7123,13 +7123,11 @@ static int
int_param(int *dst, VALUE param, VALUE sym) int_param(int *dst, VALUE param, VALUE sym)
{ {
VALUE val = rb_hash_aref(param, sym); VALUE val = rb_hash_aref(param, sym);
switch (TYPE(val)) { if (FIXNUM_P(val)) {
case T_NIL:
return FALSE;
case T_FIXNUM:
*dst = FIX2INT(val); *dst = FIX2INT(val);
return TRUE; return TRUE;
default: }
else if (!NIL_P(val)) {
rb_raise(rb_eTypeError, "invalid %+"PRIsVALUE" Fixnum: %+"PRIsVALUE, rb_raise(rb_eTypeError, "invalid %+"PRIsVALUE" Fixnum: %+"PRIsVALUE,
sym, val); sym, val);
} }
@ -7251,8 +7249,7 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params,
#undef INT_PARAM #undef INT_PARAM
} }
switch (TYPE(arg_opt_labels)) { if (RB_TYPE_P(arg_opt_labels, T_ARRAY)) {
case T_ARRAY:
len = RARRAY_LENINT(arg_opt_labels); len = RARRAY_LENINT(arg_opt_labels);
iseq->body->param.flags.has_opt = !!(len - 1 >= 0); iseq->body->param.flags.has_opt = !!(len - 1 >= 0);
@ -7268,19 +7265,16 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params,
iseq->body->param.opt_num = len - 1; iseq->body->param.opt_num = len - 1;
iseq->body->param.opt_table = opt_table; iseq->body->param.opt_table = opt_table;
} }
case T_NIL: }
break; else if (!NIL_P(arg_opt_labels)) {
default:
rb_raise(rb_eTypeError, ":opt param is not an array: %+"PRIsVALUE, rb_raise(rb_eTypeError, ":opt param is not an array: %+"PRIsVALUE,
arg_opt_labels); arg_opt_labels);
} }
switch (TYPE(keywords)) { if (RB_TYPE_P(keywords, T_ARRAY)) {
case T_ARRAY:
iseq->body->param.keyword = iseq_build_kw(iseq, params, keywords); iseq->body->param.keyword = iseq_build_kw(iseq, params, keywords);
case T_NIL: }
break; else if (!NIL_P(keywords)) {
default:
rb_raise(rb_eTypeError, ":keywords param is not an array: %+"PRIsVALUE, rb_raise(rb_eTypeError, ":keywords param is not an array: %+"PRIsVALUE,
keywords); keywords);
} }