From 1ca0db5421c0737088112d55475d37bd7f3d0bb4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 28 Jun 2011 11:36:11 -0700 Subject: [PATCH] rustc: Add a "type-owns-heap-mem" cache. 2x translation speedup. --- src/comp/middle/ty.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 486ef17bb1c8..5bf0c281f67b 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -217,6 +217,7 @@ type ctxt = creader_cache rcache, hashmap[t, str] short_names_cache, hashmap[t, bool] has_pointer_cache, + hashmap[t, bool] owns_heap_mem_cache, hashmap[@ast::ty, option::t[t]] ast_ty_to_ty_cache); type ty_ctxt = ctxt; @@ -413,6 +414,8 @@ fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs, str](ty::hash_ty, ty::eq_ty), has_pointer_cache=map::mk_hashmap[ty::t, bool](ty::hash_ty, ty::eq_ty), + owns_heap_mem_cache=map::mk_hashmap[ty::t, + bool](ty::hash_ty, ty::eq_ty), ast_ty_to_ty_cache=map::mk_hashmap[@ast::ty, option::t[t]](ast::hash_ty, ast::eq_ty)); @@ -1172,6 +1175,11 @@ fn type_is_signed(&ctxt cx, &t ty) -> bool { } fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool { + alt (cx.owns_heap_mem_cache.find(ty)) { + case (some(?result)) { ret result; } + case (none) { /* fall through */ } + } + auto result = false; alt (struct(cx, ty)) { case (ty_ivec(_)) { result = true; } @@ -1228,6 +1236,8 @@ fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool { case (ty_var(_)) { fail "ty_var in type_owns_heap_mem"; } case (ty_param(_)) { result = false; } } + + cx.owns_heap_mem_cache.insert(ty, result); ret result; }