diff options
author | Jose <jose@zeroc.com> | 2012-08-10 19:05:05 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2012-08-10 19:05:05 +0200 |
commit | dac1de9cee466c49bb66d1fa3ff3e7f8ce74b41d (patch) | |
tree | e21599db79868ffc65be32b4dda2056af9e18b0b /cpp/src/Ice/HashUtil.h | |
parent | Remove some more VC6 compiler fixes (diff) | |
download | ice-dac1de9cee466c49bb66d1fa3ff3e7f8ce74b41d.tar.bz2 ice-dac1de9cee466c49bb66d1fa3ff3e7f8ce74b41d.tar.xz ice-dac1de9cee466c49bb66d1fa3ff3e7f8ce74b41d.zip |
ICE-4702 - Poor hash algorithm
Diffstat (limited to 'cpp/src/Ice/HashUtil.h')
-rw-r--r-- | cpp/src/Ice/HashUtil.h | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/cpp/src/Ice/HashUtil.h b/cpp/src/Ice/HashUtil.h index 7b6c7f6a27b..d23ee90ff0c 100644 --- a/cpp/src/Ice/HashUtil.h +++ b/cpp/src/Ice/HashUtil.h @@ -15,13 +15,13 @@ namespace IceInternal inline void hashAdd(Ice::Int& hashCode, Ice::Int value) { - hashCode = hashCode * 5 + value; + hashCode = ((hashCode << 5) + hashCode) ^ (2654435761u * value); } inline void hashAdd(Ice::Int& hashCode, bool value) { - hashCode = hashCode * 5 + static_cast<Ice::Int>(value); + hashCode = ((hashCode << 5) + hashCode) ^ (value ? 1 : 0); } inline void @@ -29,7 +29,7 @@ hashAdd(Ice::Int& hashCode, const std::string& value) { for(std::string::const_iterator p = value.begin(); p != value.end(); ++p) { - hashCode = 5 * hashCode + *p; + hashCode = ((hashCode << 5) + hashCode) ^ *p; } } @@ -52,5 +52,4 @@ hashAdd(Ice::Int& hashCode, const std::map<K, V>& map) } } - } |