summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-15 04:38:50 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-15 04:38:50 +0000
commitb9d29603375d17c3d1d609d9662f50beaec61fa1 (patch)
treea98fe974e912c9b12d92412495b0e44676233f0b /hash.c
parentf344841e30618373889d13f5eb43cf8add194f10 (diff)
* hash.c (rb_hash_each_pair): performance improvement by using
rb_block_arity(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 182a856a38..6cddb8cf0b 100644
--- a/hash.c
+++ b/hash.c
@@ -1472,6 +1472,13 @@ each_pair_i(VALUE key, VALUE value)
return ST_CONTINUE;
}
+static int
+each_pair_i_fast(VALUE key, VALUE value)
+{
+ rb_yield_values(2, key, value);
+ return ST_CONTINUE;
+}
+
/*
* call-seq:
* hsh.each {| key, value | block } -> hsh
@@ -1498,7 +1505,10 @@ static VALUE
rb_hash_each_pair(VALUE hash)
{
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
- rb_hash_foreach(hash, each_pair_i, 0);
+ if (rb_block_arity() > 1)
+ rb_hash_foreach(hash, each_pair_i_fast, 0);
+ else
+ rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}