summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 07:49:24 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 07:49:24 (GMT)
commit98e65d9d921ec810bbae2233b80e865e76dd8502 (patch)
tree16ce055f3f2dfcedef55c4649e5eb3d7bf707040 /time.c
parent0cd28199e50039e9425f10b880c436d3ecacde0b (diff)
Prefer rb_check_arity when 0 or 1 arguments
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/time.c b/time.c
index f1cb7b6..5c4a7f2 100644
--- a/time.c
+++ b/time.c
@@ -3764,9 +3764,8 @@ static VALUE
time_localtime_m(int argc, VALUE *argv, VALUE time)
{
VALUE off;
- rb_scan_args(argc, argv, "01", &off);
- if (!NIL_P(off)) {
+ if (rb_check_arity(argc, 0, 1) && !NIL_P(off = argv[0])) {
return time_zonelocal(time, off);
}
@@ -3881,9 +3880,8 @@ static VALUE
time_getlocaltime(int argc, VALUE *argv, VALUE time)
{
VALUE off;
- rb_scan_args(argc, argv, "01", &off);
- if (!NIL_P(off)) {
+ if (rb_check_arity(argc, 0, 1) && !NIL_P(off = argv[0])) {
VALUE zone = off;
if (maybe_tzobj_p(zone)) {
VALUE t = time_dup(time);
@@ -4136,9 +4134,7 @@ time_round(int argc, VALUE *argv, VALUE time)
long nd;
struct time_object *tobj;
- rb_scan_args(argc, argv, "01", &ndigits);
-
- if (NIL_P(ndigits))
+ if (!rb_check_arity(argc, 0, 1) || NIL_P(ndigits = argv[0]))
ndigits = INT2FIX(0);
else
ndigits = rb_to_int(ndigits);