[前][次][番号順一覧][スレッド一覧]

ruby-changes:47672

From: nobu <ko1@a...>
Date: Sat, 9 Sep 2017 18:17:02 +0900 (JST)
Subject: [ruby-changes:47672] nobu:r59788 (trunk): compile.c: replaced switch by TYPE

nobu	2017-09-09 18:16:56 +0900 (Sat, 09 Sep 2017)

  New Revision: 59788

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59788

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

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 59787)
+++ compile.c	(revision 59788)
@@ -7123,13 +7123,11 @@ static int https://github.com/ruby/ruby/blob/trunk/compile.c#L7123
 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, https://github.com/ruby/ruby/blob/trunk/compile.c#L7249
 #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, https://github.com/ruby/ruby/blob/trunk/compile.c#L7265
 	    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);
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]