summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/HashUtil.h
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2012-08-10 19:05:05 +0200
committerJose <jose@zeroc.com>2012-08-10 19:05:05 +0200
commitdac1de9cee466c49bb66d1fa3ff3e7f8ce74b41d (patch)
treee21599db79868ffc65be32b4dda2056af9e18b0b /cpp/src/Ice/HashUtil.h
parentRemove some more VC6 compiler fixes (diff)
downloadice-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.h7
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)
}
}
-
}