@@ -26,7 +26,6 @@ crate enum ExternalLocation {
26
26
/// Builds the search index from the collected metadata
27
27
crate fn build_index < ' tcx > ( krate : & clean:: Crate , cache : & mut Cache , tcx : TyCtxt < ' tcx > ) -> String {
28
28
let mut defid_to_pathid = FxHashMap :: default ( ) ;
29
- let mut crate_items = Vec :: with_capacity ( cache. search_index . len ( ) ) ;
30
29
let mut crate_paths = vec ! [ ] ;
31
30
32
31
// Attach all orphan items to the type's definition if the type
@@ -77,34 +76,38 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
77
76
78
77
// Reduce `DefId` in paths into smaller sequential numbers,
79
78
// and prune the paths that do not appear in the index.
80
- let mut lastpath = String :: new ( ) ;
79
+ let mut lastpath = "" ;
81
80
let mut lastpathid = 0usize ;
82
81
83
- for item in search_index {
84
- item. parent_idx = item. parent . and_then ( |defid| match defid_to_pathid. entry ( defid) {
85
- Entry :: Occupied ( entry) => Some ( * entry. get ( ) ) ,
86
- Entry :: Vacant ( entry) => {
87
- let pathid = lastpathid;
88
- entry. insert ( pathid) ;
89
- lastpathid += 1 ;
82
+ let crate_items: Vec < & IndexItem > = search_index
83
+ . iter_mut ( )
84
+ . map ( |item| {
85
+ item. parent_idx = item. parent . and_then ( |defid| match defid_to_pathid. entry ( defid) {
86
+ Entry :: Occupied ( entry) => Some ( * entry. get ( ) ) ,
87
+ Entry :: Vacant ( entry) => {
88
+ let pathid = lastpathid;
89
+ entry. insert ( pathid) ;
90
+ lastpathid += 1 ;
90
91
91
- if let Some ( & ( ref fqp, short) ) = paths. get ( & defid) {
92
- crate_paths. push ( ( short, fqp. last ( ) . unwrap ( ) . clone ( ) ) ) ;
93
- Some ( pathid)
94
- } else {
95
- None
92
+ if let Some ( & ( ref fqp, short) ) = paths. get ( & defid) {
93
+ crate_paths. push ( ( short, fqp. last ( ) . unwrap ( ) . clone ( ) ) ) ;
94
+ Some ( pathid)
95
+ } else {
96
+ None
97
+ }
96
98
}
99
+ } ) ;
100
+
101
+ // Omit the parent path if it is same to that of the prior item.
102
+ if lastpath == & item. path {
103
+ item. path . clear ( ) ;
104
+ } else {
105
+ lastpath = & item. path ;
97
106
}
98
- } ) ;
99
107
100
- // Omit the parent path if it is same to that of the prior item.
101
- if lastpath == item. path {
102
- item. path . clear ( ) ;
103
- } else {
104
- lastpath = item. path . clone ( ) ;
105
- }
106
- crate_items. push ( & * item) ;
107
- }
108
+ & * item
109
+ } )
110
+ . collect ( ) ;
108
111
109
112
struct CrateData < ' a > {
110
113
doc : String ,
0 commit comments