From e9bb167bfb16c63099af8d0a16d297beffd5184b Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 10 Apr 2016 21:59:02 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/file.c b/file.c index 81c4f07f5d..bcadaefd9e 100644 --- a/file.c +++ b/file.c @@ -3644,14 +3644,8 @@ rb_file_expand_path_fast(VALUE fname, VALUE dname) 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 dname) 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, VALUE path, int strict) 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, VALUE klass) 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) 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); -- cgit v1.2.3