@@ -211,6 +211,9 @@ type mt = {ty: t, mut: ast::mutability};
211
211
// the types of AST nodes.
212
212
type creader_cache = hashmap < { cnum: int , pos : uint , len : uint } , ty:: t > ;
213
213
214
+ type tag_var_cache =
215
+ @smallintmap:: smallintmap < @mutable [ variant_info ] > ;
216
+
214
217
tag cast_type {
215
218
/* cast may be ignored after substituting primitive with machine types
216
219
since expr already has the right type */
@@ -234,7 +237,8 @@ type ctxt =
234
237
short_names_cache : hashmap < t , @str > ,
235
238
needs_drop_cache : hashmap < t , bool > ,
236
239
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 } ;
238
242
239
243
type ty_ctxt = ctxt ;
240
244
@@ -433,7 +437,8 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map,
433
437
needs_drop_cache: map:: mk_hashmap ( ty:: hash_ty, ty:: eq_ty) ,
434
438
kind_cache: map:: mk_hashmap ( ty:: hash_ty, ty:: eq_ty) ,
435
439
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 ( ) } ;
437
442
populate_type_store ( cx) ;
438
443
ret cx;
439
444
}
@@ -2720,6 +2725,11 @@ type variant_info = {args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
2720
2725
2721
2726
fn tag_variants ( cx : ctxt , id : ast:: def_id ) -> [ variant_info ] {
2722
2727
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
+ }
2723
2733
let item =
2724
2734
alt cx. items . find ( id. node ) {
2725
2735
some ( i) { i }
@@ -2729,7 +2739,7 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
2729
2739
ast_map : : node_item ( item) {
2730
2740
alt item. node {
2731
2741
ast:: item_tag ( variants, _) {
2732
- let result: [ variant_info ] = [ ] ;
2742
+ let result: @mutable [ variant_info ] = @mutable [ ] ;
2733
2743
for variant: ast:: variant in variants {
2734
2744
let ctor_ty = node_id_to_monotype ( cx, variant. node . id ) ;
2735
2745
let arg_tys: [ t ] = [ ] ;
@@ -2739,12 +2749,13 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
2739
2749
}
2740
2750
}
2741
2751
let did = variant. node . id ;
2742
- result +=
2752
+ * result +=
2743
2753
[ { args: arg_tys,
2744
2754
ctor_ty: ctor_ty,
2745
2755
id: ast_util:: local_def ( did) } ] ;
2746
2756
}
2747
- ret result;
2757
+ smallintmap:: insert ( * cx. tag_var_cache , id. node as uint , result) ;
2758
+ ret * result;
2748
2759
}
2749
2760
}
2750
2761
}
0 commit comments