mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b0ec083a20
commit
4b85e88174
5 changed files with 9 additions and 22 deletions
17
array.c
17
array.c
|
@ -2590,13 +2590,7 @@ rb_ary_rotate(VALUE ary, long cnt)
|
|||
static VALUE
|
||||
rb_ary_rotate_bang(int argc, VALUE *argv, VALUE ary)
|
||||
{
|
||||
long n = 1;
|
||||
|
||||
switch (argc) {
|
||||
case 1: n = NUM2LONG(argv[0]);
|
||||
case 0: break;
|
||||
default: rb_scan_args(argc, argv, "01", NULL);
|
||||
}
|
||||
long n = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
|
||||
rb_ary_rotate(ary, n);
|
||||
return ary;
|
||||
}
|
||||
|
@ -2623,13 +2617,8 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary)
|
|||
{
|
||||
VALUE rotated;
|
||||
const VALUE *ptr;
|
||||
long len, cnt = 1;
|
||||
|
||||
switch (argc) {
|
||||
case 1: cnt = NUM2LONG(argv[0]);
|
||||
case 0: break;
|
||||
default: rb_scan_args(argc, argv, "01", NULL);
|
||||
}
|
||||
long len;
|
||||
long cnt = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
|
||||
|
||||
len = RARRAY_LEN(ary);
|
||||
rotated = rb_ary_new2(len);
|
||||
|
|
|
@ -1491,7 +1491,7 @@ nucomp_rationalize(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
get_dat1(self);
|
||||
|
||||
rb_scan_args(argc, argv, "01", NULL);
|
||||
rb_check_arity(argc, 0, 1);
|
||||
|
||||
if (!k_exact_zero_p(dat->imag)) {
|
||||
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
|
||||
|
|
|
@ -2121,7 +2121,7 @@ nilclass_to_r(VALUE self)
|
|||
static VALUE
|
||||
nilclass_rationalize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
rb_scan_args(argc, argv, "01", NULL);
|
||||
rb_check_arity(argc, 0, 1);
|
||||
return nilclass_to_r(self);
|
||||
}
|
||||
|
||||
|
@ -2150,7 +2150,7 @@ integer_to_r(VALUE self)
|
|||
static VALUE
|
||||
integer_rationalize(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
rb_scan_args(argc, argv, "01", NULL);
|
||||
rb_check_arity(argc, 0, 1);
|
||||
return integer_to_r(self);
|
||||
}
|
||||
|
||||
|
|
6
re.c
6
re.c
|
@ -3960,13 +3960,11 @@ match_setter(VALUE val)
|
|||
static VALUE
|
||||
rb_reg_s_last_match(int argc, VALUE *argv)
|
||||
{
|
||||
VALUE nth;
|
||||
|
||||
if (argc > 0 && rb_scan_args(argc, argv, "01", &nth) == 1) {
|
||||
if (rb_check_arity(argc, 0, 1) == 1) {
|
||||
VALUE match = rb_backref_get();
|
||||
int n;
|
||||
if (NIL_P(match)) return Qnil;
|
||||
n = match_backref_number(match, nth);
|
||||
n = match_backref_number(match, argv[0]);
|
||||
return rb_reg_nth_match(n, match);
|
||||
}
|
||||
return match_getter();
|
||||
|
|
2
time.c
2
time.c
|
@ -4959,7 +4959,7 @@ time_dump(int argc, VALUE *argv, VALUE time)
|
|||
{
|
||||
VALUE str;
|
||||
|
||||
rb_scan_args(argc, argv, "01", 0);
|
||||
rb_check_arity(argc, 0, 1);
|
||||
str = time_mdump(time);
|
||||
|
||||
return str;
|
||||
|
|
Loading…
Reference in a new issue