about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-06-18 00:41:25 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-06-18 00:41:25 -0700
commit2ba7729ae742d163e79cf47f9d6de4856ccb1bfa (patch)
tree7092de2320172dc192d28f7b895582214153aff0 /src/comp
parentb2bcafe6fd525d52f84088309cc5a3c307397bf2 (diff)
downloadrust-2ba7729ae742d163e79cf47f9d6de4856ccb1bfa.tar.gz
rust-2ba7729ae742d163e79cf47f9d6de4856ccb1bfa.zip
rustc: Cache results of type_has_pointers. 70% translation speedup.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/ty.rs48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 17af83bf7b2..89b375287be 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -65,6 +65,7 @@ type ctxt =
         type_cache tcache,
         creader_cache rcache,
         hashmap[t, str] short_names_cache,
+        hashmap[t, bool] has_pointer_cache,
         hashmap[@ast::ty, option::t[t]] ast_ty_to_ty_cache);
 
 type ty_ctxt = ctxt;
@@ -264,6 +265,8 @@ fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs) -> ctxt {
             rcache=mk_rcache(),
             short_names_cache=map::mk_hashmap[ty::t,
                                               str](ty::hash_ty, ty::eq_ty),
+            has_pointer_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));
@@ -836,32 +839,33 @@ fn type_is_scalar(&ctxt cx, &t ty) -> bool {
 }
 
 fn type_has_pointers(&ctxt cx, &t ty) -> bool {
+    alt (cx.has_pointer_cache.find(ty)) {
+        case (some(?result)) { ret result; }
+        case (none) { /* fall through */ }
+    }
+
+    auto result = false;
     alt (struct(cx, ty)) {
-        case (
-             // scalar types
-             ty_nil) {
-            ret false;
-        }
-        case (ty_bot) { ret false; }
-        case (ty_bool) { ret false; }
-        case (ty_int) { ret false; }
-        case (ty_float) { ret false; }
-        case (ty_uint) { ret false; }
-        case (ty_machine(_)) { ret false; }
-        case (ty_char) { ret false; }
-        case (ty_type) { ret false; }
-        case (ty_native) { ret false; }
+        // scalar types
+        case (ty_nil) { /* no-op */ }
+        case (ty_bot) { /* no-op */ }
+        case (ty_bool) { /* no-op */ }
+        case (ty_int) { /* no-op */ }
+        case (ty_float) { /* no-op */ }
+        case (ty_uint) { /* no-op */ }
+        case (ty_machine(_)) { /* no-op */ }
+        case (ty_char) { /* no-op */ }
+        case (ty_type) { /* no-op */ }
+        case (ty_native) { /* no-op */ }
         case (ty_tup(?elts)) {
             for (mt m in elts) {
-                if (type_has_pointers(cx, m.ty)) { ret true; }
+                if (type_has_pointers(cx, m.ty)) { result = true; }
             }
-            ret false;
         }
         case (ty_rec(?flds)) {
             for (field f in flds) {
-                if (type_has_pointers(cx, f.mt.ty)) { ret true; }
+                if (type_has_pointers(cx, f.mt.ty)) { result = true; }
             }
-            ret false;
         }
         case (ty_tag(?did, ?tps)) {
             auto variants = tag_variants(cx, did);
@@ -870,12 +874,14 @@ fn type_has_pointers(&ctxt cx, &t ty) -> bool {
                 // Perform any type parameter substitutions.
 
                 tup_ty = substitute_type_params(cx, tps, tup_ty);
-                if (type_has_pointers(cx, tup_ty)) { ret true; }
+                if (type_has_pointers(cx, tup_ty)) { result = true; }
             }
-            ret false;
         }
-        case (_) { ret true; }
+        case (_) { result = true; }
     }
+
+    cx.has_pointer_cache.insert(ty, result);
+    ret result;
 }