ruby-changes:42400
From: nobu <ko1@a...>
Date: Sat, 2 Apr 2016 14:36:52 +0900 (JST)
Subject: [ruby-changes:42400] nobu:r54474 (trunk): numeric.c: prefer rb_check_arity
nobu 2016-04-02 15:33:26 +0900 (Sat, 02 Apr 2016) New Revision: 54474 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54474 Log: numeric.c: prefer rb_check_arity * numeric.c (flo_round, int_to_s, int_round): use rb_check_arity instead of rb_scan_args for a simple optional argument. Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 54473) +++ numeric.c (revision 54474) @@ -1842,14 +1842,13 @@ flo_truncate(VALUE num); https://github.com/ruby/ruby/blob/trunk/numeric.c#L1842 static VALUE flo_round(int argc, VALUE *argv, VALUE num) { - VALUE nd; double number, f; int ndigits = 0; int binexp; enum {float_dig = DBL_DIG+2}; - if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) { - ndigits = NUM2INT(nd); + if (rb_check_arity(argc, 0, 1)) { + ndigits = NUM2INT(argv[0]); } if (ndigits < 0) { return rb_int_round(flo_truncate(num), ndigits); @@ -3015,13 +3014,10 @@ int_to_s(int argc, VALUE *argv, VALUE x) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3014 { int base; - if (argc == 0) base = 10; - else { - VALUE b; - - rb_scan_args(argc, argv, "01", &b); - base = NUM2INT(b); - } + if (rb_check_arity(argc, 0, 1)) + base = NUM2INT(argv[0]); + else + base = 10; return rb_int2str(x, base); } @@ -4142,12 +4138,10 @@ int_dotimes(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4138 static VALUE int_round(int argc, VALUE* argv, VALUE num) { - VALUE n; int ndigits; - if (argc == 0) return num; - rb_scan_args(argc, argv, "1", &n); - ndigits = NUM2INT(n); + if (!rb_check_arity(argc, 0, 1)) return num; + ndigits = NUM2INT(argv[0]); if (ndigits > 0) { return rb_Float(num); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/