diff options
author | Jb Evain <jb@evain.net> | 2017-03-17 22:00:50 +0300 |
---|---|---|
committer | Jb Evain <jb@evain.net> | 2017-03-17 22:00:50 +0300 |
commit | 103b566a7256bc15821db99f44b8b393e3d1862c (patch) | |
tree | 0f215fb867790f5ff07f4e50fa642735a25c2271 /Mono.Cecil.PE | |
parent | faab1cffba5f3fec4f3df4e1777442c9edf6c000 (diff) |
Fix style and refactor for master integration
Diffstat (limited to 'Mono.Cecil.PE')
-rw-r--r-- | Mono.Cecil.PE/ByteBufferEqualityComparer.cs | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/Mono.Cecil.PE/ByteBufferEqualityComparer.cs b/Mono.Cecil.PE/ByteBufferEqualityComparer.cs index dd3a145..8b7cb23 100644 --- a/Mono.Cecil.PE/ByteBufferEqualityComparer.cs +++ b/Mono.Cecil.PE/ByteBufferEqualityComparer.cs @@ -32,29 +32,17 @@ namespace Mono.Cecil.PE { public int GetHashCode (ByteBuffer buffer) { -#if !BYTE_BUFFER_WELL_DISTRIBUTED_HASH - var hash = 0; - var bytes = buffer.buffer; - for (int i = 0; i < buffer.length; i++) - hash = (hash * 37) ^ bytes [i]; - - return hash; -#else - const uint p = 16777619; - uint hash = 2166136261; + // See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function + const int fnv_offset_bias = unchecked((int)2166136261); + const int fnv_prime = 16777619; + var hash_code = fnv_offset_bias; var bytes = buffer.buffer; - for (int i = 0; i < buffer.length; i++) - hash = (hash ^ bytes [i]) * p; - hash += hash << 13; - hash ^= hash >> 7; - hash += hash << 3; - hash ^= hash >> 17; - hash += hash << 5; + for (int i = 0; i < buffer.length; i++) + hash_code = unchecked ((hash_code ^ bytes [i]) * fnv_prime); - return (int) hash; -#endif - } + return hash_code; + } } } |