summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-21 13:24:33 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-21 13:24:33 +0000
commitcc410660021e1c8f68b9799efea66cf1aa2267b9 (patch)
treec4f8c35b29dd7b8441d0dba11a9da2b2961bf69c /class.c
parentceea7ecef997411098fc0db3726897debbd9cdbf (diff)
* include/ruby/ruby.h (rb_scan_args): use __VA_ARGS__ instead of
va_arg to allow compilers optimize more aggressive. https://gustedt.wordpress.com/2011/07/10/avoid-writing-va_arg-functions/ rb_scan_args is now expected to be statically resolved. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c135
1 files changed, 0 insertions, 135 deletions
diff --git a/class.c b/class.c
index 0261838..62be074 100644
--- a/class.c
+++ b/class.c
@@ -1754,141 +1754,6 @@ rb_obj_basic_to_s_p(VALUE obj)
return 0;
}
-#include <stdarg.h>
-
-int
-rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
-{
- int i;
- const char *p = fmt;
- VALUE *var;
- va_list vargs;
- int f_var = 0, f_hash = 0, f_block = 0;
- int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
- int argi = 0;
- VALUE hash = Qnil;
-
- if (ISDIGIT(*p)) {
- n_lead = *p - '0';
- p++;
- if (ISDIGIT(*p)) {
- n_opt = *p - '0';
- p++;
- if (ISDIGIT(*p)) {
- n_trail = *p - '0';
- p++;
- goto block_arg;
- }
- }
- }
- if (*p == '*') {
- f_var = 1;
- p++;
- if (ISDIGIT(*p)) {
- n_trail = *p - '0';
- p++;
- }
- }
- block_arg:
- if (*p == ':') {
- f_hash = 1;
- p++;
- }
- if (*p == '&') {
- f_block = 1;
- p++;
- }
- if (*p != '\0') {
- rb_fatal("bad scan arg format: %s", fmt);
- }
- n_mand = n_lead + n_trail;
-
- if (argc < n_mand)
- goto argc_error;
-
- va_start(vargs, fmt);
-
- /* capture an option hash - phase 1: pop */
- if (f_hash && n_mand < argc) {
- VALUE last = argv[argc - 1];
-
- if (NIL_P(last)) {
- /* nil is taken as an empty option hash only if it is not
- ambiguous; i.e. '*' is not specified and arguments are
- given more than sufficient */
- if (!f_var && n_mand + n_opt < argc)
- argc--;
- }
- else {
- hash = rb_check_hash_type(last);
- if (!NIL_P(hash)) {
- VALUE opts = rb_extract_keywords(&hash);
- if (!hash) argc--;
- hash = opts ? opts : Qnil;
- }
- }
- }
- /* capture leading mandatory arguments */
- for (i = n_lead; i-- > 0; ) {
- var = va_arg(vargs, VALUE *);
- if (var) *var = argv[argi];
- argi++;
- }
- /* capture optional arguments */
- for (i = n_opt; i-- > 0; ) {
- var = va_arg(vargs, VALUE *);
- if (argi < argc - n_trail) {
- if (var) *var = argv[argi];
- argi++;
- }
- else {
- if (var) *var = Qnil;
- }
- }
- /* capture variable length arguments */
- if (f_var) {
- int n_var = argc - argi - n_trail;
-
- var = va_arg(vargs, VALUE *);
- if (0 < n_var) {
- if (var) *var = rb_ary_new4(n_var, &argv[argi]);
- argi += n_var;
- }
- else {
- if (var) *var = rb_ary_new();
- }
- }
- /* capture trailing mandatory arguments */
- for (i = n_trail; i-- > 0; ) {
- var = va_arg(vargs, VALUE *);
- if (var) *var = argv[argi];
- argi++;
- }
- /* capture an option hash - phase 2: assignment */
- if (f_hash) {
- var = va_arg(vargs, VALUE *);
- if (var) *var = hash;
- }
- /* capture iterator block */
- if (f_block) {
- var = va_arg(vargs, VALUE *);
- if (rb_block_given_p()) {
- *var = rb_block_proc();
- }
- else {
- *var = Qnil;
- }
- }
- va_end(vargs);
-
- if (argi < argc) {
- argc_error:
- rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
- }
-
- return argc;
-}
-
VALUE
rb_keyword_error_new(const char *error, VALUE keys)
{