[前][次][番号順一覧][スレッド一覧]

ruby-changes:29932

From: glass <ko1@a...>
Date: Mon, 15 Jul 2013 13:39:00 +0900 (JST)
Subject: [ruby-changes:29932] glass:r41984 (trunk): * hash.c (rb_hash_each_pair): performance improvement by using

glass	2013-07-15 13:38:50 +0900 (Mon, 15 Jul 2013)

  New Revision: 41984

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41984

  Log:
    * hash.c (rb_hash_each_pair): performance improvement by using
      rb_block_arity().

  Modified files:
    trunk/ChangeLog
    trunk/hash.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41983)
+++ ChangeLog	(revision 41984)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 15 13:36:02 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* hash.c (rb_hash_each_pair): performance improvement by using
+	  rb_block_arity().
+
 Mon Jul 15 13:15:37 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* proc.c (rb_block_arity): create internal API rb_block_arity().
Index: hash.c
===================================================================
--- hash.c	(revision 41983)
+++ hash.c	(revision 41984)
@@ -1472,6 +1472,13 @@ each_pair_i(VALUE key, VALUE value) https://github.com/ruby/ruby/blob/trunk/hash.c#L1472
     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 https://github.com/ruby/ruby/blob/trunk/hash.c#L1505
 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;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]