From 98e65d9d921ec810bbae2233b80e865e76dd8502 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 6 Dec 2018 07:49:24 +0000 Subject: 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 --- variable.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 968d404c05..89befc0c89 100644 --- a/variable.c +++ b/variable.c @@ -2728,16 +2728,11 @@ rb_const_list(void *data) VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE mod) { - VALUE inherit; + bool inherit = TRUE; - if (argc == 0) { - inherit = Qtrue; - } - else { - rb_scan_args(argc, argv, "01", &inherit); - } + if (rb_check_arity(argc, 0, 1)) inherit = RTEST(argv[0]); - if (RTEST(inherit)) { + if (inherit) { return rb_const_list(rb_mod_const_of(mod, 0)); } else { @@ -3294,16 +3289,11 @@ cvar_list(void *data) VALUE rb_mod_class_variables(int argc, const VALUE *argv, VALUE mod) { - VALUE inherit; + bool inherit = TRUE; st_table *tbl; - if (argc == 0) { - inherit = Qtrue; - } - else { - rb_scan_args(argc, argv, "01", &inherit); - } - if (RTEST(inherit)) { + if (rb_check_arity(argc, 0, 1)) inherit = RTEST(argv[0]); + if (inherit) { tbl = mod_cvar_of(mod, 0); } else { -- cgit v1.2.3