Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: third_party/WebKit/Source/wtf/HashFunctions.h

Issue 2469893005: Correct truncation behaviour in WTF::hashInts() (Closed)
Patch Set: remove test logic Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/HashFunctions.h
diff --git a/third_party/WebKit/Source/wtf/HashFunctions.h b/third_party/WebKit/Source/wtf/HashFunctions.h
index f54c2f0b6bbceb4e94959538e11e5189dd496ec5..c3d90d02655a162d8249f943f79fab200715aa95 100644
--- a/third_party/WebKit/Source/wtf/HashFunctions.h
+++ b/third_party/WebKit/Source/wtf/HashFunctions.h
@@ -111,11 +111,12 @@ inline unsigned hashInt(uint64_t key) {
inline unsigned hashInts(unsigned key1, unsigned key2) {
unsigned shortRandom1 = 277951225; // A random 32-bit value.
unsigned shortRandom2 = 95187966; // A random 32-bit value.
- uint64_t longRandom = 19248658165952622LL; // A random 64-bit value.
+ uint64_t longRandom = 19248658165952623LL; // A random, odd 64-bit value.
- uint64_t product = longRandom * (shortRandom1 * key1 + shortRandom2 * key2);
- unsigned highBits =
- static_cast<unsigned>(product >> (sizeof(uint64_t) - sizeof(unsigned)));
+ uint64_t product =
+ longRandom * shortRandom1 * key1 + longRandom * shortRandom2 * key2;
+ unsigned highBits = static_cast<unsigned>(
+ product >> (8 * (sizeof(uint64_t) - sizeof(unsigned))));
return highBits;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698