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

ruby-changes:39004

From: nobu <ko1@a...>
Date: Wed, 1 Jul 2015 17:17:16 +0900 (JST)
Subject: [ruby-changes:39004] nobu:r51085 (trunk): struct.c: AREF_HASH_UNIT enum

nobu	2015-07-01 17:17:02 +0900 (Wed, 01 Jul 2015)

  New Revision: 51085

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

  Log:
    struct.c: AREF_HASH_UNIT enum
    
    * struct.c (AREF_HASH_UNIT): name a magic number, which is shared
      by struct_member_pos_probe and struct_set_members.

  Modified files:
    trunk/struct.c
Index: struct.c
===================================================================
--- struct.c	(revision 51084)
+++ struct.c	(revision 51085)
@@ -15,6 +15,7 @@ https://github.com/ruby/ruby/blob/trunk/struct.c#L15
 
 /* only for struct[:field] access */
 enum {
+    AREF_HASH_UNIT = 5,
     AREF_HASH_THRESHOLD = 10
 };
 
@@ -82,8 +83,8 @@ struct_member_pos_ideal(VALUE name, long https://github.com/ruby/ruby/blob/trunk/struct.c#L83
 static long
 struct_member_pos_probe(long prev, long mask)
 {
-    /* (((prev/2) * 5 + 1) & (mask/2)) * 2 */
-    return (prev * 5 + 2) & mask;
+    /* (((prev/2) * AREF_HASH_UNIT + 1) & (mask/2)) * 2 */
+    return (prev * AREF_HASH_UNIT + 2) & mask;
 }
 
 static VALUE
@@ -99,7 +100,7 @@ struct_set_members(VALUE klass, VALUE /* https://github.com/ruby/ruby/blob/trunk/struct.c#L100
 	long i, j, mask = 64;
 	VALUE name;
 
-	while (mask < members_length * 5) mask *= 2;
+	while (mask < members_length * AREF_HASH_UNIT) mask *= 2;
 
 	back = rb_ary_tmp_new(mask + 1);
 	rb_ary_store(back, mask, INT2FIX(members_length));

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

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