From b3d3d52cd69cb6ea3848e5eb5b4b18318850142f Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 24 May 2016 15:23:06 +0000 Subject: ruby.h: optimize rb_scan_args_set * include/ruby/ruby.h (rb_scan_args_set): check the arity after adjusting argc for an option hash, for optimization in simpler cases. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- include/ruby/ruby.h | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'include/ruby/ruby.h') diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index de61ced053..b7ee5db942 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -2245,16 +2245,9 @@ rb_scan_args_set(int argc, const VALUE *argv, int f_var, int f_hash, int f_block, int varc, VALUE *vars[]) { - int i; - int n_mand; - VALUE *var; - int argi = 0, vari = 0; - VALUE hash = Qnil; - - n_mand = n_lead + n_trail; - - if (argc < n_mand) - goto argc_error; + int i, argi = 0, vari = 0; + VALUE *var, hash = Qnil; + const int n_mand = n_lead + n_trail; /* capture an option hash - phase 1: pop */ if (f_hash && n_mand < argc) { @@ -2276,6 +2269,9 @@ rb_scan_args_set(int argc, const VALUE *argv, } } } + + rb_check_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt); + /* capture leading mandatory arguments */ for (i = n_lead; i-- > 0; ) { var = vars[vari++]; @@ -2328,11 +2324,6 @@ rb_scan_args_set(int argc, const VALUE *argv, } } - if (argi < argc) { - argc_error: - rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt); - } - return argc; } #endif -- cgit v1.2.3