Skip to content

Commit a1b3e3e

Browse files
committed
rustc: Cache results of ty::tag_variants
1 parent 68c6272 commit a1b3e3e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Diff for: src/comp/middle/ty.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ type mt = {ty: t, mut: ast::mutability};
211211
// the types of AST nodes.
212212
type creader_cache = hashmap<{cnum: int, pos: uint, len: uint}, ty::t>;
213213

214+
type tag_var_cache =
215+
@smallintmap::smallintmap<@mutable [variant_info]>;
216+
214217
tag cast_type {
215218
/* cast may be ignored after substituting primitive with machine types
216219
since expr already has the right type */
@@ -234,7 +237,8 @@ type ctxt =
234237
short_names_cache: hashmap<t, @str>,
235238
needs_drop_cache: hashmap<t, bool>,
236239
kind_cache: hashmap<t, ast::kind>,
237-
ast_ty_to_ty_cache: hashmap<@ast::ty, option::t<t>>};
240+
ast_ty_to_ty_cache: hashmap<@ast::ty, option::t<t>>,
241+
tag_var_cache: tag_var_cache};
238242

239243
type ty_ctxt = ctxt;
240244

@@ -433,7 +437,8 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map,
433437
needs_drop_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
434438
kind_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
435439
ast_ty_to_ty_cache:
436-
map::mk_hashmap(ast_util::hash_ty, ast_util::eq_ty)};
440+
map::mk_hashmap(ast_util::hash_ty, ast_util::eq_ty),
441+
tag_var_cache: @smallintmap::mk()};
437442
populate_type_store(cx);
438443
ret cx;
439444
}
@@ -2720,6 +2725,11 @@ type variant_info = {args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
27202725

27212726
fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
27222727
if ast::local_crate != id.crate { ret csearch::get_tag_variants(cx, id); }
2728+
assert (id.node >= 0);
2729+
alt smallintmap::find(*cx.tag_var_cache, id.node as uint) {
2730+
option::some(variants) { ret *variants; }
2731+
_ { /* fallthrough */ }
2732+
}
27232733
let item =
27242734
alt cx.items.find(id.node) {
27252735
some(i) { i }
@@ -2729,7 +2739,7 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
27292739
ast_map::node_item(item) {
27302740
alt item.node {
27312741
ast::item_tag(variants, _) {
2732-
let result: [variant_info] = [];
2742+
let result: @mutable [variant_info] = @mutable [];
27332743
for variant: ast::variant in variants {
27342744
let ctor_ty = node_id_to_monotype(cx, variant.node.id);
27352745
let arg_tys: [t] = [];
@@ -2739,12 +2749,13 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
27392749
}
27402750
}
27412751
let did = variant.node.id;
2742-
result +=
2752+
*result +=
27432753
[{args: arg_tys,
27442754
ctor_ty: ctor_ty,
27452755
id: ast_util::local_def(did)}];
27462756
}
2747-
ret result;
2757+
smallintmap::insert(*cx.tag_var_cache, id.node as uint, result);
2758+
ret *result;
27482759
}
27492760
}
27502761
}

0 commit comments

Comments
 (0)