summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 07:49:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 07:49:24 +0000
commit98e65d9d921ec810bbae2233b80e865e76dd8502 (patch)
tree16ce055f3f2dfcedef55c4649e5eb3d7bf707040 /enumerator.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 'enumerator.c')
-rw-r--r--enumerator.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/enumerator.c b/enumerator.c
index e84785a6b8..615f933778 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -604,12 +604,9 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
{
VALUE memo;
- rb_scan_args(argc, argv, "01", &memo);
+ rb_check_arity(argc, 0, 1);
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_enum_size);
- if (NIL_P(memo))
- memo = INT2FIX(0);
- else
- memo = rb_to_int(memo);
+ memo = (!argc || NIL_P(memo = argv[0])) ? INT2FIX(0) : rb_to_int(memo);
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)MEMO_NEW(memo, 0, 0));
}