diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-21 12:05:41 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-21 12:05:41 +0000 |
commit | 33e8eef020018693e93e5df85655a8e8e0042d69 (patch) | |
tree | 4d3dd109ac10cfcc6808b422a5de589a2a8ef961 /time.c | |
parent | 23ba6b2eb9258ed1354d3deeeeb610ef079f81b4 (diff) |
time.c: use RB_TYPE_P
* time.c (time_timespec): use RB_TYPE_P instead of switching by
TYPE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -2220,15 +2220,13 @@ time_timespec(VALUE num, int interval) 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) 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) rb_raise(rb_eTypeError, "can't convert %"PRIsVALUE" into %s", rb_obj_class(num), tstr); } - break; } return t; } |