From 6c3c48e3d569a40774a14a5bfbebf3fc72874de0 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 9 Sep 2017 09:16:56 +0000 Subject: 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 --- compile.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 203dce4a96..9f49db4748 100644 --- a/compile.c +++ b/compile.c @@ -7123,13 +7123,11 @@ static int int_param(int *dst, VALUE param, VALUE sym) { VALUE val = rb_hash_aref(param, sym); - switch (TYPE(val)) { - case T_NIL: - return FALSE; - case T_FIXNUM: + if (FIXNUM_P(val)) { *dst = FIX2INT(val); return TRUE; - default: + } + else if (!NIL_P(val)) { rb_raise(rb_eTypeError, "invalid %+"PRIsVALUE" Fixnum: %+"PRIsVALUE, sym, val); } @@ -7251,8 +7249,7 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params, #undef INT_PARAM } - switch (TYPE(arg_opt_labels)) { - case T_ARRAY: + if (RB_TYPE_P(arg_opt_labels, T_ARRAY)) { len = RARRAY_LENINT(arg_opt_labels); 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_table = opt_table; } - case T_NIL: - break; - default: + } + else if (!NIL_P(arg_opt_labels)) { rb_raise(rb_eTypeError, ":opt param is not an array: %+"PRIsVALUE, arg_opt_labels); } - switch (TYPE(keywords)) { - case T_ARRAY: + if (RB_TYPE_P(keywords, T_ARRAY)) { iseq->body->param.keyword = iseq_build_kw(iseq, params, keywords); - case T_NIL: - break; - default: + } + else if (!NIL_P(keywords)) { rb_raise(rb_eTypeError, ":keywords param is not an array: %+"PRIsVALUE, keywords); } -- cgit v1.2.3