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
This commit is contained in:
nobu 2018-12-06 07:49:24 +00:00
parent 0cd28199e5
commit 98e65d9d92
18 changed files with 72 additions and 139 deletions

View file

@ -4115,10 +4115,9 @@ econv_putback(int argc, VALUE *argv, VALUE self)
int putbackable;
VALUE str, max;
rb_scan_args(argc, argv, "01", &max);
if (NIL_P(max))
if (!rb_check_arity(argc, 0, 1) || NIL_P(max = argv[0])) {
n = rb_econv_putbackable(ec);
}
else {
n = NUM2INT(max);
putbackable = rb_econv_putbackable(ec);