diff options
| author | Patrick Walton <[email protected]> | 2011-03-31 11:55:28 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-31 11:55:28 -0700 |
| commit | 6a60cb1e0cf4bdc37e78c0560e6fed0743a9c271 (patch) | |
| tree | 5bc001a208290212ca3d0f4fe1a992b5e7e81754 /src/comp/util/common.rs | |
| parent | stdlib: Add a write_be_uint() function to writers (diff) | |
| download | rust-6a60cb1e0cf4bdc37e78c0560e6fed0743a9c271.tar.xz rust-6a60cb1e0cf4bdc37e78c0560e6fed0743a9c271.zip | |
rustc: Mix the bits more when hashing def ids
Diffstat (limited to 'src/comp/util/common.rs')
| -rw-r--r-- | src/comp/util/common.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index c7d94279..5243e2f7 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 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; - } +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; +} - let std.map.hashfn[ast.def_id] hasher = hash; +fn new_def_hash[V]() -> std.map.hashmap[ast.def_id,V] { + 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); } |