summaryrefslogtreecommitdiff
path: root/enum.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 /enum.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 'enum.c')
-rw-r--r--enum.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/enum.c b/enum.c
index f446403..a739d33 100644
--- a/enum.c
+++ b/enum.c
@@ -2009,11 +2009,11 @@ enum_min_by(int argc, VALUE *argv, VALUE obj)
struct MEMO *memo;
VALUE num;
- rb_scan_args(argc, argv, "01", &num);
+ rb_check_arity(argc, 0, 1);
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_size);
- if (!NIL_P(num))
+ if (argc && !NIL_P(num = argv[0]))
return rb_nmin_run(obj, num, 1, 0, 0);
memo = MEMO_NEW(Qundef, Qnil, 0);
@@ -2116,11 +2116,11 @@ enum_max_by(int argc, VALUE *argv, VALUE obj)
struct MEMO *memo;
VALUE num;
- rb_scan_args(argc, argv, "01", &num);
+ rb_check_arity(argc, 0, 1);
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_size);
- if (!NIL_P(num))
+ if (argc && !NIL_P(num = argv[0]))
return rb_nmin_run(obj, num, 1, 1, 0);
memo = MEMO_NEW(Qundef, Qnil, 0);
@@ -2971,10 +2971,10 @@ enum_cycle(int argc, VALUE *argv, VALUE obj)
VALUE nv = Qnil;
long n, i, len;
- rb_scan_args(argc, argv, "01", &nv);
+ rb_check_arity(argc, 0, 1);
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_cycle_size);
- if (NIL_P(nv)) {
+ if (!argc || NIL_P(nv = argv[0])) {
n = -1;
}
else {
@@ -3944,11 +3944,8 @@ enum_sum(int argc, VALUE* argv, VALUE obj)
VALUE beg, end;
int excl;
- if (rb_scan_args(argc, argv, "01", &memo.v) == 0)
- memo.v = LONG2FIX(0);
-
+ memo.v = (rb_check_arity(argc, 0, 1) == 0) ? LONG2FIX(0) : argv[0];
memo.block_given = rb_block_given_p();
-
memo.n = 0;
memo.r = Qundef;