improve iterator randomization
authorYves Orton <demerphq@gmail.com>
Sun, 24 Mar 2013 10:46:22 +0000 (11:46 +0100)
committerYves Orton <demerphq@gmail.com>
Sun, 24 Mar 2013 10:50:18 +0000 (11:50 +0100)
hv.c

index 0821841..1a4558f 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -792,10 +792,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
      * making it harder to see if there is a collision. We also
      * reset the iterator randomizer if there is one.
      */
-    if (SvOOK(hv))
-        HvAUX(hv)->xhv_rand= (U32)PL_hash_rand_bits;
     PL_hash_rand_bits += (PTRV)entry ^ hash; /* we don't bother to use ptr_hash here */
-    PL_hash_rand_bits= ROTL_UV(PL_hash_rand_bits,1);
     if ( !*oentry || (PL_hash_rand_bits & 1) ) {
         HeNEXT(entry) = *oentry;
         *oentry = entry;
@@ -803,6 +800,10 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
         HeNEXT(entry) = HeNEXT(*oentry);
         HeNEXT(*oentry) = entry;
     }
+    PL_hash_rand_bits= ROTL_UV(PL_hash_rand_bits,1);
+    if (SvOOK(hv)) {
+        HvAUX(hv)->xhv_rand= (U32)PL_hash_rand_bits;
+    }
 
     if (val == &PL_sv_placeholder)
        HvPLACEHOLDERS(hv)++;