Skip to content

Commit 2e6711f

Browse files
committed
Small fast-path hack to ty.hash_ty and eq_ty.
1 parent 1080ac5 commit 2e6711f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/comp/middle/ty.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,57 @@ fn def_to_str(ast.def_id did) -> str {
661661
ret #fmt("%d:%d", did._0, did._1);
662662
}
663663

664+
fn simple_ty_code(&@t ty) -> uint {
665+
alt (ty.struct) {
666+
case (ty_nil) { ret 0u; }
667+
case (ty_bool) { ret 1u; }
668+
case (ty_int) { ret 2u; }
669+
case (ty_float) { ret 3u; }
670+
case (ty_uint) { ret 4u; }
671+
case (ty_machine(?tm)) {
672+
alt (tm) {
673+
case (common.ty_i8) { ret 5u; }
674+
case (common.ty_i16) { ret 6u; }
675+
case (common.ty_i32) { ret 7u; }
676+
case (common.ty_i64) { ret 8u; }
677+
678+
case (common.ty_u8) { ret 9u; }
679+
case (common.ty_u16) { ret 10u; }
680+
case (common.ty_u32) { ret 11u; }
681+
case (common.ty_u64) { ret 12u; }
682+
683+
case (common.ty_f32) { ret 13u; }
684+
case (common.ty_f64) { ret 14u; }
685+
}
686+
}
687+
case (ty_char) { ret 15u; }
688+
case (ty_str) { ret 16u; }
689+
case (ty_task) { ret 17u; }
690+
case (ty_type) { ret 18u; }
691+
case (ty_native) { ret 19u; }
692+
case (_) {
693+
}
694+
}
695+
ret 0xffffu;
696+
}
697+
664698
fn hash_ty(&@t ty) -> uint {
699+
auto s = simple_ty_code(ty);
700+
if (s != 0xffffu) {
701+
ret s;
702+
}
665703
auto f = def_to_str;
666704
ret _str.hash(metadata.ty_str(ty, f));
667705
}
668706

669707
fn eq_ty(&@t a, &@t b) -> bool {
708+
709+
auto sa = simple_ty_code(a);
710+
if (sa != 0xffffu) {
711+
auto sb = simple_ty_code(b);
712+
ret sa == sb;
713+
}
714+
670715
// FIXME: this is gross, but I think it's safe, and I don't think writing
671716
// a giant function to handle all the cases is necessary when structural
672717
// equality will someday save the day.

0 commit comments

Comments
 (0)