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;
|
interval = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (TYPE(num)) {
|
if (FIXNUM_P(num)) {
|
||||||
case T_FIXNUM:
|
|
||||||
t.tv_sec = NUM2TIMET(num);
|
t.tv_sec = NUM2TIMET(num);
|
||||||
if (interval && t.tv_sec < 0)
|
if (interval && t.tv_sec < 0)
|
||||||
rb_raise(rb_eArgError, "%s must be positive", tstr);
|
rb_raise(rb_eArgError, "%s must be positive", tstr);
|
||||||
t.tv_nsec = 0;
|
t.tv_nsec = 0;
|
||||||
break;
|
}
|
||||||
|
else if (RB_FLOAT_TYPE_P(num)) {
|
||||||
case T_FLOAT:
|
|
||||||
if (interval && RFLOAT_VALUE(num) < 0.0)
|
if (interval && RFLOAT_VALUE(num) < 0.0)
|
||||||
rb_raise(rb_eArgError, "%s must be positive", tstr);
|
rb_raise(rb_eArgError, "%s must be positive", tstr);
|
||||||
else {
|
else {
|
||||||
@ -2251,16 +2249,14 @@ time_timespec(VALUE num, int interval)
|
|||||||
rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
|
rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(num));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
else if (RB_TYPE_P(num, T_BIGNUM)) {
|
||||||
case T_BIGNUM:
|
|
||||||
t.tv_sec = NUM2TIMET(num);
|
t.tv_sec = NUM2TIMET(num);
|
||||||
if (interval && t.tv_sec < 0)
|
if (interval && t.tv_sec < 0)
|
||||||
rb_raise(rb_eArgError, "%s must be positive", tstr);
|
rb_raise(rb_eArgError, "%s must be positive", tstr);
|
||||||
t.tv_nsec = 0;
|
t.tv_nsec = 0;
|
||||||
break;
|
}
|
||||||
|
else {
|
||||||
default:
|
|
||||||
i = INT2FIX(1);
|
i = INT2FIX(1);
|
||||||
ary = rb_check_funcall(num, id_divmod, 1, &i);
|
ary = rb_check_funcall(num, id_divmod, 1, &i);
|
||||||
if (ary != Qundef && !NIL_P(ary = rb_check_array_type(ary))) {
|
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_raise(rb_eTypeError, "can't convert %"PRIsVALUE" into %s",
|
||||||
rb_obj_class(num), tstr);
|
rb_obj_class(num), tstr);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user