diff options
author | Cedric BAIL <cedric.bail@free.fr> | 2013-02-06 06:56:42 +0000 |
---|---|---|
committer | Cedric BAIL <cedric.bail@free.fr> | 2013-02-06 06:56:42 +0000 |
commit | 2fdedc3c18f0d77ee652e3ae91d7865390836a57 (patch) | |
tree | 455faa20cffcd14a133b90e6f2643694c89f5ca7 /src | |
parent | 0d725bafadabdc070f10724270db8cdbecaac939 (diff) | |
download | eina-2fdedc3c18f0d77ee652e3ae91d7865390836a57.tar.gz |
eina: backport r83578.
SVN revision: 83652
Diffstat (limited to 'src')
-rw-r--r-- | src/include/eina_inline_hash.x | 14 | ||||
-rw-r--r-- | src/lib/eina_hash.c | 2 | ||||
-rw-r--r-- | src/lib/eina_main.c | 5 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/include/eina_inline_hash.x b/src/include/eina_inline_hash.x index be20e8f..b2fc3f3 100644 --- a/src/include/eina_inline_hash.x +++ b/src/include/eina_inline_hash.x @@ -19,6 +19,8 @@ #ifndef EINA_INLINE_HASH_X_ #define EINA_INLINE_HASH_X_ +EAPI extern unsigned int eina_seed; + /* djb2 hash algorithm was first reported by dan bernstein, and was the old default hash function for evas. @@ -26,7 +28,7 @@ static inline int eina_hash_djb2(const char *key, int len) { - unsigned int hash_num = 5381; + unsigned int hash_num = 5381 ^ eina_seed; const unsigned char *ptr; if (!key) return 0; @@ -39,7 +41,7 @@ eina_hash_djb2(const char *key, int len) static inline int eina_hash_djb2_len(const char *key, int *plen) { - unsigned int hash_num = 5381; + unsigned int hash_num = 5381 ^ eina_seed; int len = 0; const unsigned char *ptr; @@ -64,7 +66,7 @@ eina_hash_int32(const unsigned int *pkey, int len) key ^= key >> 12; key += key << 2; key ^= key >> 4; - key *= 2057; + key *= 2057 ^ eina_seed; key ^= key >> 16; return key; } @@ -78,7 +80,7 @@ eina_hash_int64(const unsigned long int *pkey, int len) key = ~key + (key << 18); key ^= key >> 31; - key *= 21; + key *= 21 ^ eina_seed; key ^= key >> 11; key += key << 6; key ^= key >> 22; @@ -107,8 +109,8 @@ eina_hash_murmur3(const char *key, int len) const unsigned char * data = (const unsigned char*)key; const int nblocks = len / 4; unsigned int h1 = 0, k1; - unsigned int c1 = 0xcc9e2d51; - unsigned int c2 = 0x1b873593; + unsigned int c1 = 0xcc9e2d51 ^ eina_seed; + unsigned int c2 = 0x1b873593 ^ eina_seed; const unsigned int * blocks = (const unsigned int *)(data + nblocks*4); int i; const unsigned char *tail; diff --git a/src/lib/eina_hash.c b/src/lib/eina_hash.c index 821d225..37b7751 100644 --- a/src/lib/eina_hash.c +++ b/src/lib/eina_hash.c @@ -1328,7 +1328,7 @@ eina_hash_iterator_tuple_new(const Eina_Hash *hash) EAPI int eina_hash_superfast(const char *key, int len) { - int hash = len, tmp; + int hash = len ^ eina_seed, tmp; int rem; rem = len & 3; diff --git a/src/lib/eina_main.c b/src/lib/eina_main.c index e6236b9..e94a78a 100644 --- a/src/lib/eina_main.c +++ b/src/lib/eina_main.c @@ -101,6 +101,7 @@ static int _eina_log_dom = -1; EAPI Eina_Bool _eina_threads_activated = EINA_FALSE; EAPI Eina_Error EINA_ERROR_NOT_MAIN_LOOP = 0; +EAPI unsigned int eina_seed = 0; static const char EINA_ERROR_NOT_MAIN_LOOP_STR[] = "Main loop thread check failed."; @@ -245,6 +246,10 @@ eina_init(void) if (EINA_LIKELY(_eina_main_count > 0)) return ++_eina_main_count; + srand(time(NULL)); + while (eina_seed == 0) + eina_seed = rand(); + #ifdef MT if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE"))) { |