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

ruby-changes:34639

From: nobu <ko1@a...>
Date: Sun, 6 Jul 2014 23:44:59 +0900 (JST)
Subject: [ruby-changes:34639] nobu:r46722 (trunk): st.c: re-calc hash_val before adding

nobu	2014-07-06 23:42:57 +0900 (Sun, 06 Jul 2014)

  New Revision: 46722

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

  Log:
    st.c: re-calc hash_val before adding
    
    * st.c (st_update): re-calculate hash_val before adding if key was
      changed, otherwise cannot access the newly added element if it
      has different hash value.

  Modified files:
    trunk/st.c
Index: st.c
===================================================================
--- st.c	(revision 46721)
+++ st.c	(revision 46722)
@@ -843,6 +843,7 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L843
 	    switch (retval) {
 	      case ST_CONTINUE:
 		if (!existing) {
+		    if (key != old_key) hash_val = do_hash(key, table);
 		    add_packed_direct(table, key, value, hash_val);
 		    break;
 		}
@@ -878,6 +879,7 @@ st_update(st_table *table, st_data_t key https://github.com/ruby/ruby/blob/trunk/st.c#L879
 	switch (retval) {
 	  case ST_CONTINUE:
 	    if (!existing) {
+		if (key != old_key) hash_val = do_hash(key, table);
 		add_direct(table, key, value, hash_val, hash_pos(hash_val, table->num_bins));
 		break;
 	    }

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

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