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
This commit is contained in:
parent
23ba6b2eb9
commit
33e8eef020
19
time.c
19
time.c
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user