From 6c95e400d82699887b66f5de0fef2bb5e1f8cc32 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 7 Dec 2011 07:21:07 -0800 Subject: [PATCH] repair more hash functions --- src/comp/middle/ty.rs | 30 +++++++++++++++--------------- src/comp/syntax/ast_util.rs | 2 +- src/libstd/str.rs | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index b5b5559f4aa..022b249674b 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -1299,23 +1299,23 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t { fn hash_type_structure(st: sty) -> uint { fn hash_uint(id: uint, n: uint) -> uint { let h = id; - h += h << 5u + n; + h += (h << 5u) + n; ret h; } fn hash_def(id: uint, did: ast::def_id) -> uint { let h = id; - h += h << 5u + (did.crate as uint); - h += h << 5u + (did.node as uint); + h += (h << 5u) + (did.crate as uint); + h += (h << 5u) + (did.node as uint); ret h; } fn hash_subty(id: uint, subty: t) -> uint { let h = id; - h += h << 5u + hash_ty(subty); + h += (h << 5u) + hash_ty(subty); ret h; } fn hash_type_constr(id: uint, c: @type_constr) -> uint { let h = id; - h += h << 5u + hash_def(h, c.node.id); + h += (h << 5u) + hash_def(h, c.node.id); ret hash_type_constr_args(h, c.node.args); } fn hash_type_constr_args(id: uint, args: [@ty_constr_arg]) -> uint { @@ -1338,8 +1338,8 @@ fn hash_type_structure(st: sty) -> uint { fn hash_fn(id: uint, args: [arg], rty: t) -> uint { let h = id; - for a: arg in args { h += h << 5u + hash_ty(a.ty); } - h += h << 5u + hash_ty(rty); + for a: arg in args { h += (h << 5u) + hash_ty(a.ty); } + h += (h << 5u) + hash_ty(rty); ret h; } alt st { @@ -1366,19 +1366,19 @@ fn hash_type_structure(st: sty) -> uint { ty_str. { ret 17u; } ty_tag(did, tys) { let h = hash_def(18u, did); - for typ: t in tys { h += h << 5u + hash_ty(typ); } + for typ: t in tys { h += (h << 5u) + hash_ty(typ); } ret h; } ty_box(mt) { ret hash_subty(19u, mt.ty); } ty_vec(mt) { ret hash_subty(21u, mt.ty); } ty_rec(fields) { let h = 26u; - for f: field in fields { h += h << 5u + hash_ty(f.mt.ty); } + for f: field in fields { h += (h << 5u) + hash_ty(f.mt.ty); } ret h; } ty_tup(ts) { let h = 25u; - for tt in ts { h += h << 5u + hash_ty(tt); } + for tt in ts { h += (h << 5u) + hash_ty(tt); } ret h; } @@ -1389,7 +1389,7 @@ fn hash_type_structure(st: sty) -> uint { ty_native_fn(args, rty) { ret hash_fn(28u, args, rty); } ty_obj(methods) { let h = 29u; - for m: method in methods { h += h << 5u + str::hash(m.ident); } + for m: method in methods { h += (h << 5u) + str::hash(m.ident); } ret h; } ty_var(v) { ret hash_uint(30u, v as uint); } @@ -1400,15 +1400,15 @@ fn hash_type_structure(st: sty) -> uint { ty_ptr(mt) { ret hash_subty(35u, mt.ty); } ty_res(did, sub, tps) { let h = hash_subty(hash_def(18u, did), sub); - for tp: t in tps { h += h << 5u + hash_ty(tp); } + for tp: t in tps { h += (h << 5u) + hash_ty(tp); } ret h; } ty_constr(t, cs) { let h = 36u; - for c: @type_constr in cs { h += h << 5u + hash_type_constr(h, c); } + for c: @type_constr in cs { h += (h << 5u) + hash_type_constr(h, c); } ret h; } - ty_uniq(mt) { let h = 37u; h += h << 5u + hash_ty(mt.ty); ret h; } + ty_uniq(mt) { let h = 37u; h += (h << 5u) + hash_ty(mt.ty); ret h; } } } @@ -1416,7 +1416,7 @@ fn hash_type_info(st: sty, cname_opt: option::t) -> uint { let h = hash_type_structure(st); alt cname_opt { none. {/* no-op */ } - some(s) { h += h << 5u + str::hash(s); } + some(s) { h += (h << 5u) + str::hash(s); } } ret h; } diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index f39b5865c25..60b3f2b6fa4 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -199,7 +199,7 @@ fn hash_ty(&&t: @ty) -> uint { } fn hash_def_id(&&id: def_id) -> uint { - id.crate as uint << 16u + (id.node as uint) + (id.crate as uint << 16u) + (id.node as uint) } fn eq_def_id(&&a: def_id, &&b: def_id) -> bool { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 2bae8d699a5..521dc33758e 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -324,7 +324,7 @@ fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} { // Clunky way to get the right bits from the first byte. Uses two shifts, // the first to clip off the marker bits at the left of the byte, and then // a second (as uint) to get it to the right position. - val += (b0 << (w + 1u as u8) as uint) << (w - 1u) * 6u - w - 1u; + val += (b0 << (w + 1u as u8) as uint) << ((w - 1u) * 6u - w - 1u); ret {ch: val as char, next: i}; }