ruby-changes:42458
From: nobu <ko1@a...>
Date: Mon, 11 Apr 2016 06:02:34 +0900 (JST)
Subject: [ruby-changes:42458] nobu:r54533 (trunk): file.c: prefer rb_check_arity
nobu 2016-04-11 06:59:02 +0900 (Mon, 11 Apr 2016) New Revision: 54533 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54533 Log: file.c: prefer rb_check_arity * file.c (rb_file_s_expand_path, rb_file_s_absolute_path): use rb_check_arity instead of rb_scan_args for a simple optional argument. * file.c (rb_file_s_realpath, rb_file_s_realdirpath): ditto. * file.c (rb_file_s_basename): ditto. Modified files: trunk/file.c Index: file.c =================================================================== --- file.c (revision 54532) +++ file.c (revision 54533) @@ -3644,14 +3644,8 @@ rb_file_expand_path_fast(VALUE fname, VA https://github.com/ruby/ruby/blob/trunk/file.c#L3644 VALUE rb_file_s_expand_path(int argc, const VALUE *argv) { - VALUE fname, dname; - - if (argc == 1) { - return rb_file_expand_path(argv[0], Qnil); - } - rb_scan_args(argc, argv, "11", &fname, &dname); - - return rb_file_expand_path(fname, dname); + rb_check_arity(argc, 1, 2); + return rb_file_expand_path(argv[0], argc > 1 ? argv[1] : Qnil); } VALUE @@ -3677,14 +3671,8 @@ rb_file_absolute_path(VALUE fname, VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L3671 VALUE rb_file_s_absolute_path(int argc, const VALUE *argv) { - VALUE fname, dname; - - if (argc == 1) { - return rb_file_absolute_path(argv[0], Qnil); - } - rb_scan_args(argc, argv, "11", &fname, &dname); - - return rb_file_absolute_path(fname, dname); + rb_check_arity(argc, 1, 2); + return rb_file_absolute_path(argv[0], argc > 1 ? argv[1] : Qnil); } static void @@ -3897,8 +3885,8 @@ rb_realpath_internal(VALUE basedir, VALU https://github.com/ruby/ruby/blob/trunk/file.c#L3885 static VALUE rb_file_s_realpath(int argc, VALUE *argv, VALUE klass) { - VALUE path, basedir; - rb_scan_args(argc, argv, "11", &path, &basedir); + VALUE basedir = (rb_check_arity(argc, 1, 2) > 1) ? argv[1] : Qnil; + VALUE path = argv[0]; FilePathValue(path); return rb_realpath_internal(basedir, path, 1); } @@ -3918,8 +3906,8 @@ rb_file_s_realpath(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/file.c#L3906 static VALUE rb_file_s_realdirpath(int argc, VALUE *argv, VALUE klass) { - VALUE path, basedir; - rb_scan_args(argc, argv, "11", &path, &basedir); + VALUE basedir = (rb_check_arity(argc, 1, 2) > 1) ? argv[1] : Qnil; + VALUE path = argv[0]; FilePathValue(path); return rb_realpath_internal(basedir, path, 0); } @@ -4048,10 +4036,13 @@ rb_file_s_basename(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/file.c#L4036 long f, n; rb_encoding *enc; - if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) { + fext = Qnil; + if (rb_check_arity(argc, 1, 2) == 2) { + fext = argv[1]; StringValue(fext); enc = check_path_encoding(fext); } + fname = argv[0]; FilePathStringValue(fname); if (NIL_P(fext) || !(enc = rb_enc_compatible(fname, fext))) { enc = rb_enc_get(fname); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/