diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-09-13 16:42:27 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-13 16:42:27 -0700 |
commit | 3cfbfa9628435e3b09316a18c2db9e4f250fdd77 (patch) | |
tree | aac052f5a518c9b4aaf296da2a4730c72e5ed521 /enumerator.c | |
parent | 24b1b339757ecab4539a2cb00a545bfcf885d3ef (diff) |
Consolidate empty keyword handling
Remove rb_add_empty_keyword, and instead of calling that every
place you need to add empty keyword hashes, run that code in
a single static function in vm_eval.c.
Add 4 defines to include/ruby/ruby.h, these are to be used as
int kw_splat values when calling the various rb_*_kw functions:
RB_NO_KEYWORDS :: Do not pass keywords
RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords
RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords
RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was
called with (for method delegation)
rb_empty_keyword_given_p needs to stay. It is required if argument
delegation is done but delayed to a later point, which Enumerator
does.
Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly
delegate keyword arguments to super method.
Diffstat (limited to 'enumerator.c')
-rw-r--r-- | enumerator.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/enumerator.c b/enumerator.c index 43008bc170..2a94aa388f 100644 --- a/enumerator.c +++ b/enumerator.c @@ -370,7 +370,7 @@ enumerator_allocate(VALUE klass) return enum_obj; } -#define PASS_KW_SPLAT (rb_empty_keyword_given_p() ? 2 : rb_keyword_given_p()) +#define PASS_KW_SPLAT (rb_empty_keyword_given_p() ? RB_PASS_EMPTY_KEYWORDS : rb_keyword_given_p()) static VALUE enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn, VALUE size, int kw_splat) @@ -386,13 +386,7 @@ enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, const VALUE *ar ptr->obj = obj; ptr->meth = rb_to_id(meth); - if (kw_splat == 2) { - if (argc) ptr->args = rb_ary_new4(argc+1, rb_add_empty_keyword(argc, argv)); - else ptr->args = rb_ary_new_from_args(1, rb_hash_new()); - kw_splat = 1; - } else { - if (argc) ptr->args = rb_ary_new4(argc, argv); - } + if (argc) ptr->args = rb_ary_new4(argc, argv); ptr->fib = 0; ptr->dst = Qnil; ptr->lookahead = Qundef; |