Skip to content

Commit 1ca0db5

Browse files
committed
rustc: Add a "type-owns-heap-mem" cache. 2x translation speedup.
1 parent 5f5b7e3 commit 1ca0db5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/comp/middle/ty.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ type ctxt =
217217
creader_cache rcache,
218218
hashmap[t, str] short_names_cache,
219219
hashmap[t, bool] has_pointer_cache,
220+
hashmap[t, bool] owns_heap_mem_cache,
220221
hashmap[@ast::ty, option::t[t]] ast_ty_to_ty_cache);
221222

222223
type ty_ctxt = ctxt;
@@ -413,6 +414,8 @@ fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs,
413414
str](ty::hash_ty, ty::eq_ty),
414415
has_pointer_cache=map::mk_hashmap[ty::t,
415416
bool](ty::hash_ty, ty::eq_ty),
417+
owns_heap_mem_cache=map::mk_hashmap[ty::t,
418+
bool](ty::hash_ty, ty::eq_ty),
416419
ast_ty_to_ty_cache=map::mk_hashmap[@ast::ty,
417420
option::t[t]](ast::hash_ty,
418421
ast::eq_ty));
@@ -1172,6 +1175,11 @@ fn type_is_signed(&ctxt cx, &t ty) -> bool {
11721175
}
11731176

11741177
fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool {
1178+
alt (cx.owns_heap_mem_cache.find(ty)) {
1179+
case (some(?result)) { ret result; }
1180+
case (none) { /* fall through */ }
1181+
}
1182+
11751183
auto result = false;
11761184
alt (struct(cx, ty)) {
11771185
case (ty_ivec(_)) { result = true; }
@@ -1228,6 +1236,8 @@ fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool {
12281236
case (ty_var(_)) { fail "ty_var in type_owns_heap_mem"; }
12291237
case (ty_param(_)) { result = false; }
12301238
}
1239+
1240+
cx.owns_heap_mem_cache.insert(ty, result);
12311241
ret result;
12321242
}
12331243

0 commit comments

Comments
 (0)