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

ruby-changes:45066

From: nobu <ko1@a...>
Date: Wed, 21 Dec 2016 21:05:46 +0900 (JST)
Subject: [ruby-changes:45066] nobu:r57139 (trunk): time.c: use RB_TYPE_P

nobu	2016-12-21 21:05:41 +0900 (Wed, 21 Dec 2016)

  New Revision: 57139

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

  Log:
    time.c: use RB_TYPE_P
    
    * time.c (time_timespec): use RB_TYPE_P instead of switching by
      TYPE.

  Modified files:
    trunk/time.c
Index: time.c
===================================================================
--- time.c	(revision 57138)
+++ time.c	(revision 57139)
@@ -2220,15 +2220,13 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2220
     interval = 1;
 #endif
 
-    switch (TYPE(num)) {
-      case T_FIXNUM:
+    if (FIXNUM_P(num)) {
 	t.tv_sec = NUM2TIMET(num);
 	if (interval && t.tv_sec < 0)
 	    rb_raise(rb_eArgError, "%s must be positive", tstr);
 	t.tv_nsec = 0;
-	break;
-
-      case T_FLOAT:
+    }
+    else if (RB_FLOAT_TYPE_P(num)) {
 	if (interval && RFLOAT_VALUE(num) < 0.0)
 	    rb_raise(rb_eArgError, "%s must be positive", tstr);
 	else {
@@ -2251,16 +2249,14 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2249
 		rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
 	    }
 	}
-	break;
-
-      case T_BIGNUM:
+    }
+    else if (RB_TYPE_P(num, T_BIGNUM)) {
 	t.tv_sec = NUM2TIMET(num);
 	if (interval && t.tv_sec < 0)
 	    rb_raise(rb_eArgError, "%s must be positive", tstr);
 	t.tv_nsec = 0;
-	break;
-
-      default:
+    }
+    else {
 	i = INT2FIX(1);
 	ary = rb_check_funcall(num, id_divmod, 1, &i);
 	if (ary != Qundef && !NIL_P(ary = rb_check_array_type(ary))) {
@@ -2276,7 +2272,6 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2272
 	    rb_raise(rb_eTypeError, "can't convert %"PRIsVALUE" into %s",
 		     rb_obj_class(num), tstr);
         }
-	break;
     }
     return t;
 }

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

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