summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-02 05:29:11 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-02 05:29:11 +0000
commit7ae65b24c26bc2dc7a0bf2fe829e3062f58e063a (patch)
treeb765ebc3636c4e8691c60436db1f325a03f63e8f /struct.c
parent487dfb9d2266e1e21fa35ad6933883a99ec7a35f (diff)
downloadruby-7ae65b24c26bc2dc7a0bf2fe829e3062f58e063a.tar.gz
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
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/struct.c b/struct.c
index b36dd37e4b..dc4f99396e 100644
--- a/struct.c
+++ b/struct.c
@@ -686,19 +686,10 @@ rb_struct_each_pair(VALUE s)
RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
members = rb_struct_members(s);
- if (rb_block_arity() > 1) {
- for (i=0; i<RSTRUCT_LEN(s); i++) {
- VALUE key = rb_ary_entry(members, i);
- VALUE value = RSTRUCT_GET(s, i);
- rb_yield_values(2, key, value);
- }
- }
- else {
- for (i=0; i<RSTRUCT_LEN(s); i++) {
- VALUE key = rb_ary_entry(members, i);
- VALUE value = RSTRUCT_GET(s, i);
- rb_yield(rb_assoc_new(key, value));
- }
+ for (i=0; i<RSTRUCT_LEN(s); i++) {
+ VALUE key = rb_ary_entry(members, i);
+ VALUE value = RSTRUCT_GET(s, i);
+ rb_yield_assoc_or_values(key, value);
}
return s;
}