From 6a60cb1e0cf4bdc37e78c0560e6fed0743a9c271 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 31 Mar 2011 11:55:28 -0700 Subject: [PATCH] rustc: Mix the bits more when hashing def ids --- src/comp/util/common.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index c7d9427947d..5243e2f7df2 100644 --- a/src/comp/util/common.rs +++ b/src/comp/util/common.rs @@ -50,16 +50,15 @@ fn def_eq(&ast.def_id a, &ast.def_id b) -> bool { ret a._0 == b._0 && a._1 == b._1; } +fn hash_def(&ast.def_id d) -> uint { + auto h = 5381u; + h = ((h << 5u) + h) ^ (d._0 as uint); + h = ((h << 5u) + h) ^ (d._1 as uint); + ret h; +} + fn new_def_hash[V]() -> std.map.hashmap[ast.def_id,V] { - - fn hash(&ast.def_id d) -> uint { - let uint u = d._0 as uint; - u <<= 16u; - u |= d._1 as uint; - ret u; - } - - let std.map.hashfn[ast.def_id] hasher = hash; + let std.map.hashfn[ast.def_id] hasher = hash_def; let std.map.eqfn[ast.def_id] eqer = def_eq; ret std.map.mk_hashmap[ast.def_id,V](hasher, eqer); }