@@ -24,6 +24,7 @@ use rustc_target::abi::{Integer, TagEncoding, Variants};
24
24
use smallvec:: SmallVec ;
25
25
26
26
use std:: fmt:: Write ;
27
+ use std:: rc:: Rc ;
27
28
28
29
// Compute the name of the type as it should be stored in debuginfo. Does not do
29
30
// any caching, i.e., calling the function twice with the same type will also do
@@ -33,14 +34,18 @@ pub fn compute_debuginfo_type_name<'tcx>(
33
34
tcx : TyCtxt < ' tcx > ,
34
35
t : Ty < ' tcx > ,
35
36
qualified : bool ,
36
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
37
+ type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , Rc < str > > ,
37
38
) -> String {
38
39
let _prof = tcx. prof . generic_activity ( "compute_debuginfo_type_name" ) ;
39
40
41
+ if let Some ( type_name) = type_name_cache. get ( & ( t, qualified) ) {
42
+ return String :: from ( & type_name[ ..] ) ;
43
+ }
44
+
40
45
let mut result = String :: with_capacity ( 64 ) ;
41
46
let mut visited = FxHashSet :: default ( ) ;
42
47
push_debuginfo_type_name ( tcx, t, qualified, & mut result, & mut visited, type_name_cache) ;
43
- if type_name_cache. insert ( ( t, qualified) , result . clone ( ) ) . is_some ( ) {
48
+ if type_name_cache. insert ( ( t, qualified) , Rc :: from ( & * result ) ) . is_some ( ) {
44
49
bug ! ( "type name is already in the type name cache!" ) ;
45
50
}
46
51
result
@@ -54,9 +59,8 @@ fn push_debuginfo_type_name<'tcx>(
54
59
qualified : bool ,
55
60
output : & mut String ,
56
61
visited : & mut FxHashSet < Ty < ' tcx > > ,
57
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
62
+ type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , Rc < str > > ,
58
63
) {
59
- // Check if we have seen this type and qualifier before.
60
64
if let Some ( type_name) = type_name_cache. get ( & ( t, qualified) ) {
61
65
output. push_str ( & type_name[ ..] ) ;
62
66
return ;
@@ -437,7 +441,7 @@ fn push_debuginfo_type_name<'tcx>(
437
441
substs : SubstsRef < ' tcx > ,
438
442
output : & mut String ,
439
443
visited : & mut FxHashSet < Ty < ' tcx > > ,
440
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
444
+ type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , Rc < str > > ,
441
445
) {
442
446
let layout = tcx. layout_of ( tcx. param_env ( def. did ) . and ( ty) ) . expect ( "layout error" ) ;
443
447
@@ -555,7 +559,7 @@ fn push_generic_params_internal<'tcx>(
555
559
substs : SubstsRef < ' tcx > ,
556
560
output : & mut String ,
557
561
visited : & mut FxHashSet < Ty < ' tcx > > ,
558
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
562
+ type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , Rc < str > > ,
559
563
) -> bool {
560
564
if substs. non_erasable_generics ( ) . next ( ) . is_none ( ) {
561
565
return false ;
@@ -642,7 +646,7 @@ pub fn push_generic_params<'tcx>(
642
646
tcx : TyCtxt < ' tcx > ,
643
647
substs : SubstsRef < ' tcx > ,
644
648
output : & mut String ,
645
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
649
+ type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , Rc < str > > ,
646
650
) {
647
651
let _prof = tcx. prof . generic_activity ( "compute_debuginfo_type_name" ) ;
648
652
let mut visited = FxHashSet :: default ( ) ;
0 commit comments