From 7ae65b24c26bc2dc7a0bf2fe829e3062f58e063a Mon Sep 17 00:00:00 2001 From: glass Date: Mon, 2 Oct 2017 05:29:11 +0000 Subject: vm_eval.c: add rb_yield_assoc_or_values() The new function rb_yield_assoc_or_values() will reduce branching. * vm_eval.c: add rb_yield_assoc_or_values() * internal.h: ditto * hash.c: use rb_yield_assoc_or_values() * struct.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_eval.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'vm_eval.c') diff --git a/vm_eval.c b/vm_eval.c index 2375e2f34b..c6ed947660 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1009,6 +1009,18 @@ rb_yield_values2(int argc, const VALUE *argv) return rb_yield_0(argc, argv); } +VALUE +rb_yield_assoc_or_values(VALUE key, VALUE value) +{ + if (rb_block_arity() > 1) { + VALUE argv[2] = { key, value }; + return rb_yield_0(2, argv); + } + else { + return rb_yield_1(rb_assoc_new(key, value)); + } +} + VALUE rb_yield_splat(VALUE values) { -- cgit v1.2.3