From abce51368c8e2b7c5d73ec13cf8f4bb01a332a25 Mon Sep 17 00:00:00 2001
From: Arne Goedeke <el@laramies.com>
Date: Wed, 6 Nov 2013 20:37:41 +0100
Subject: [PATCH] string hashing: do not change to siphash right away

---
 src/stralloc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/stralloc.c b/src/stralloc.c
index 82a805e2d3..03749645ab 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -76,8 +76,7 @@ static PIKE_MUTEX_T *bucket_locks;
 static unsigned int hash_prefix_len=64;
 static unsigned int need_more_hash_prefix_depth=0;
 
-/* Force a new hashkey to be generated early during init. */
-static unsigned int need_new_hashkey_depth=0xffff;
+static unsigned int need_new_hashkey_depth=0;
 static size_t hashkey = 0;
 
 static unsigned INT32 htable_size=0;
@@ -748,6 +747,12 @@ static void link_pike_string(struct pike_string *s, size_t hval)
      * /Hubbe
      */
 
+    if (need_new_hashkey_depth > 128) {
+      /* A simple mixing function. */
+      hashkey ^= (hashkey << 5) ^ (current_time.tv_sec ^ current_time.tv_usec);
+      need_new_hashkey_depth = 0;
+    }
+
 #ifdef PIKE_RUN_UNLOCKED
     mt_lock(bucket_locks);
     if(need_more_hash_prefix_depth <= 4)
@@ -759,9 +764,6 @@ static void link_pike_string(struct pike_string *s, size_t hval)
     for(h=1;h<BUCKET_LOCKS;h++) mt_lock(bucket_locks+h);
 #endif
 
-    /* A simple mixing function. */
-    hashkey ^= (hashkey << 5) ^ (current_time.tv_sec ^ current_time.tv_usec);
-
     if (need_more_hash_prefix_depth > 4) 
     {
       hash_prefix_len=hash_prefix_len*2;
@@ -773,7 +775,6 @@ static void link_pike_string(struct pike_string *s, size_t hval)
     /* NOTE: No need to update to the correct values, since that will
      *       be done on demand.
      */
-    need_new_hashkey_depth = 0;
     need_more_hash_prefix_depth=0;
 
     for(h=0;h<htable_size;h++)
-- 
GitLab